﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Portal.Cms.Bussiness;
using Portal.Web.Utility;
using Portal.Cms.Model;
using Portal.Utility;
using Portal.Web.Model;
using Portal.Core;
using dtSearch32Lib;
using DocumentSearchServiceModel;
using DocumentSearch32Lib;
using Portal.Systems.Model;
using Portal.Workflow.Bussiness;
using Portal.Cms.Utility;
using System.Data;

namespace Portal.Cms.Render
{
    public class CmsDataRenderBll
    {
        static string GetPlugInJavascript(string SiteId,string ParentDataId)
        {
            
            string ScriptText =
                "<input type=hidden id=txtParentDataId value=\"" + ParentDataId + "\">\r\n" +
                   "<script language=javascript>\r\n" +
                   "   function ClientUpdateIndex(GroupDataId)\r\n"+
                   "   {\r\n"+
                   "        SiteId='"+SiteId+"';\r\n"+
                   "        AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideIndex(SiteId,GroupDataId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        alert(AjaxOut.InfoMessage);\r\n" +
                   "   }\r\n"+

                   "    function ClientAdd(GroupDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        window.open('AddCmsData.aspx?gid='+GroupDataId,'_self');\r\n"+
                   //"        document.getElementById('txtDataId').value = Portal.Cms.Render.CmsDataRenderBll.ServerSideGetNewDataId(SiteId).value;\r\n" +
                   //"        document.getElementById('divActionAddForm').style.display='block';\r\n" +
                   //"        document.getElementById('divListForm').style.display='none';\r\n" +
                   //"        document.getElementById('sidebar').style.display='none';\r\n" +
                   //"        document.getElementById('txtAlias').value='';\r\n" +
                   //"        document.getElementById('txtSubject').value='';\r\n" +
                   //"        document.getElementById('txtDescription').value='';\r\n" +
                   //"        document.getElementById('txtUrl').value='';\r\n" +
                   //"        document.getElementById('txtSource').value='';\r\n" +
                   //"        document.getElementById('txtSortIndex').value='0';\r\n" +
                   //"        if(document.getElementById('txtSignDate')!=null)document.getElementById('txtSignDate').value='';\r\n" +
                   //"        if(document.getElementById('txtReleaseDate')!=null)document.getElementById('txtReleaseDate').value='';\r\n" +
                   //"        if(document.getElementById('txtEffectedDate')!=null)document.getElementById('txtEffectedDate').value='';\r\n" +
                   //"        if(document.getElementById('txtEndEffectedDate')!=null)document.getElementById('txtEndEffectedDate').value='';\r\n" +
                   //"        if(document.getElementById('txtReplaceDoc')!=null)document.getElementById('txtReplaceDoc').value='';\r\n" +
                   //"        if(document.getElementById('txtModifyDoc')!=null)document.getElementById('txtModifyDoc').value='';\r\n" +
                   //"        if(FCKeditorAPI!=null){\r\n" +
                   //"            oEditor = FCKeditorAPI.GetInstance('FCKeditorBody');\r\n" +
                   //"            if(oEditor!=null) oEditor.SetData(''); \r\n" +
                   //"        }\r\n" +
                   //"        document.getElementById('txtAlias').focus();\r\n" +
                   //"        if(document.getElementById('drpSelectDocStatus')!=null)document.getElementById('drpSelectDocStatus').selectedIndex=1;\r\n" +
                   "    }\r\n" +

                   "    function ClientChangeAvatar(GroupDataId,CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        document.getElementById('txtChangeAvatarUpdateId').value=CmsDataId;\r\n" +
                   "        document.getElementById('divActionChangeAvatarForm').style.display='block';\r\n" +
                   "        document.getElementById('sidebar').style.display='none';\r\n" +
                   "        document.getElementById('divListForm').style.display='none';\r\n" +
                   "        document.getElementById('txtSubject').focus();\r\n" +
                   "    }\r\n" +


                   "    function ClientAttachDoc(GroupDataId,CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        document.getElementById('txtChangeAttachDocUpdateId').value=CmsDataId;\r\n" +
                   "        document.getElementById('divActionAttachDocForm').style.display='block';\r\n" +
                   "        document.getElementById('divListForm').style.display='none';\r\n" +
                   "        document.getElementById('sidebar').style.display='none';\r\n" +
                   "        document.getElementById('txtSubject').focus();\r\n" +
                   "    }\r\n" +

                   "    function ClientUpdate(GroupDataId,CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        window.open('UpdateCmsData.aspx?gid='+GroupDataId+'&CmsDataId='+CmsDataId,'_self');\r\n"+
                   "    }\r\n" +

                   "    function ClientUpdateDocument(GroupDataId,CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        window.open('UpdateCmsDocumentData.aspx?gid='+GroupDataId+'&CmsDataId='+CmsDataId,'_self');\r\n" +
                   "    }\r\n" +

                   "    function ClientListAttachFile(GroupDataId,CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "    }\r\n" +


                   "    function ClientBack()\r\n" +
                   "    {\r\n" +
                   //"        document.getElementById('divActionAddForm').style.display='none';\r\n" +
                   //"        document.getElementById('divActionUpdateForm').style.display='none';\r\n" +
                   "        document.getElementById('divActionChangeAvatarForm').style.display='none';\r\n" +
                   "        document.getElementById('divActionAttachDocForm').style.display='none';\r\n" +
                   "        document.getElementById('divListForm').style.display='block';\r\n" +
                   "        document.getElementById('sidebar').style.display='block';\r\n" +
                   "    }\r\n" +



                   "    function ClientDelete(DataType,CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn xóa chưa?')==false)return;\r\n" +
                   "        ParentDataId=document.getElementById('txtParentDataId').value;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideDelete(SiteId,DataType, ParentDataId, CmsDataId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        if(AjaxOut.RetUrl!='')\r\n" +
                   "        {\r\n" +
                   "          window.open(AjaxOut.RetUrl,'_self');\r\n" +
                   "          return;\r\n"+
                   "        }\r\n" +
                   "        else\r\n"+
                   "        {\r\n"+
                   "            document.getElementById('divListForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        }\r\n"+
                   "    }\r\n" +

                   "    function ClientPublic(CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn phát hành chưa?')==false)return;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSidePublic(SiteId,CmsDataId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +

                   "        document.getElementById('divStatusText'+CmsDataId).innerHTML = AjaxOut.InfoMessage;\r\n" +
                   "        document.getElementById('divButton'+CmsDataId).innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                   "    function ClientUnPublic(CmsDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn ngưng phát hành chưa?')==false)return;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideUnPublic(SiteId,CmsDataId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divStatusText'+CmsDataId).innerHTML = AjaxOut.InfoMessage;\r\n" +
                   "        document.getElementById('divButton'+CmsDataId).innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                    "   function ClientDownloadAttachFile(DataId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideDownloadAttachFile(SiteId,DataId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_blank');\r\n" +
                    "   }\r\n" +

                   "    function ClientRelationDocument(GroupDataId,CmsDataId)\r\n"+
                   "    {\r\n"+
                   "    }\r\n"+

                   "    function ProcessHotCategory(Id)\r\n"+
                   "    {\r\n"+
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        checked=document.getElementById('chkHot'+Id).checked;\r\n"+
                   "        CheckedIds=document.getElementById('txtAddCheckedHotCategory').value;\r\n" +
                   "        CheckedIds = Portal.Cms.Render.CmsDataRenderBll.ServerSideProcessCheckCategory(SiteId,CheckedIds,Id,checked).value;\r\n" +
                   "        document.getElementById('txtAddCheckedHotCategory').value=CheckedIds;\r\n" +

                   
                   "        if(checked)\r\n"+
                   "        {\r\n"+
                   "            document.getElementById('chk'+Id).checked=true;\r\n"+

                   "            CheckedIds=document.getElementById('txtAddCheckedCategory').value;\r\n" +
                   "            CheckedIds = Portal.Cms.Render.CmsDataRenderBll.ServerSideProcessCheckCategory(SiteId,CheckedIds,Id,true).value;\r\n" +
                   "            document.getElementById('txtAddCheckedCategory').value=CheckedIds;\r\n" +


                   "        }\r\n"+
                   "    }\r\n"+

                   "    function ProcessCheckCategory(Id)\r\n" +
                   "    {\r\n" +
                   "        SiteId='"+SiteId+"';\r\n"+
                   "        checked=document.getElementById('chk'+Id).checked;\r\n" +
                   "        CheckedIds=document.getElementById('txtAddCheckedCategory').value;\r\n" +
                   "        CheckedIds = Portal.Cms.Render.CmsDataRenderBll.ServerSideProcessCheckCategory(SiteId,CheckedIds,Id,checked).value;\r\n" +
                   "        document.getElementById('txtAddCheckedCategory').value=CheckedIds;\r\n"+
                   "        if(checked==false)\r\n" +
                   "        {\r\n" +
                   "            document.getElementById('chkHot'+Id).checked=false;\r\n" +


                   "            CheckedIds=document.getElementById('txtAddCheckedHotCategory').value;\r\n" +
                   "            CheckedIds = Portal.Cms.Render.CmsDataRenderBll.ServerSideProcessCheckCategory(SiteId,CheckedIds,Id,false).value;\r\n" +
                   "            document.getElementById('txtAddCheckedHotCategory').value=CheckedIds;\r\n" +


                   "        }\r\n" +
                   "    }\r\n" +
                   "</script>\r\n";
            return ScriptText;
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideProcessCheckCategory(string SiteId,string CheckedIds,string Id,bool Checked)
        {
            if (Checked)
            {
                if (!string.IsNullOrEmpty(CheckedIds))
                {
                    CheckedIds = CheckedIds + ";";
                }
                CheckedIds = CheckedIds + Id;
            }
            else
            {
                CheckedIds = CheckedIds.Replace(Id,"");
            }
            CheckedIds = CheckedIds.Replace(";;", ";");
            if (CheckedIds.Length > 0)
            {
                if (CheckedIds[0].ToString().Equals(";"))
                {
                    CheckedIds = CheckedIds.Substring(1);
                }
            }
            return CheckedIds;
        }


        

        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string GroupDataId = (string)WebEnvironments.Request(SiteId, "gid");
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupDataPermission.StaticId, GroupDataPermission.funcAccess, GroupDataId, WebSessionUtility.GetCurrentLoginUser().UserId, true);
                string ParentDataId = (string)WebEnvironments.Request(SiteId, "parent");
                string Html =
                   GetPlugInJavascript(SiteId,ParentDataId)+
                   "<div class=FormFunction>\r\n" +
                   "    <div class=body>\r\n" +
                   "        <div id=sidebar></div>\r\n"+
                   //"        <div id=divActionUpdateForm  style=\"display:none;\">" + DrawUpdateForm(SiteId, GroupDataId).HtmlContent + "</div>\r\n" +
                   //"        <div id=divActionAddForm style=\"display:none;\">" + DrawAddForm(SiteId, GroupDataId).HtmlContent + "</div>\r\n" +
                   "        <div id=divActionChangeAvatarForm  style=\"display:none;\">" + DrawChangeAvatarForm(SiteId, GroupDataId).HtmlContent + "</div>\r\n" +
                   "        <div id=divActionAttachDocForm  style=\"display:none;\">" + DrawChangeAttachDocForm(SiteId, GroupDataId).HtmlContent + "</div>\r\n" +
                   "        <div id=divListForm class=tabcontent>\r\n" +
                                ServerSideReading(SiteId, GroupDataId, ParentDataId).HtmlContent +
                   "        </div>\r\n" +
                   "    </div>\r\n" +
                   "</div>\r\n";
                   
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            
            return OAjaxOut;
        }
        public static string BaseSiteUrl
        {
            get
            {
                HttpContext context = HttpContext.Current;
                string baseUrl = context.Request.Url.Authority + context.Request.ApplicationPath.TrimEnd('/');
                return baseUrl;
            }
        }

        public static string ConvertUrl(string Url)
        {
            Url = Url.Replace("192.168.1.2/", BaseSiteUrl + "/");
            Url = Url.Replace("117.3.4.207/", BaseSiteUrl + "/");
            return Url;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideReading(string SiteId, string GroupDataId,string ParentDataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();

                
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu này! Truy cập không hợp lệ!");
                string AppendTitle = "";
                if (string.IsNullOrEmpty(ParentDataId) == false)
                {
                    CmsDataCls SubOCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, ParentDataId);
                    AppendTitle = "<br> " + SubOCmsData.Subject;
                }
                CmsDataCls[] CmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingCmsData(SiteId, GroupDataId, ParentDataId);
                //string CodeCaption = "Mã";
                //if (OGroupData.frkDataTypeId.Equals("document"))
                //{
                //    CodeCaption = "Số văn bản";
                //}
                string ButtonUrl = WebConfig.GetButtonIconRoot(OSiteParam);

                string BackUrl = "javascript:window.open('Home.aspx','_self');";// javascript:window.open('RootGroupData.aspx?DataType=" + OGroupData.frkDataTypeId + "','_self');";
                string Html =
                   "  <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:ClientAdd('" + GroupDataId + "');\"><img class=image src=\""+ButtonUrl+"/Add.png\"><div>Thêm mới</div></li>\r\n" +
                   "            <li onclick=\"" + BackUrl + "\"><img class=image src=\""+ButtonUrl+"/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "        <h3><a href=\"InputData.aspx?gid="+OGroupData.GroupDataId+"\">" + OGroupData.GroupDataName +"</a>"+ AppendTitle+ " (" + CmsData.Length + ")</h3>\r\n" +
                   "        <table>\r\n" +
                   "                <tr>\r\n" +
                   "                    <th class=thIndex>#</th>\r\n" +
                   //"                    <th class=thAlias>" + CodeCaption + "</th>\r\n" +
                   "                    <th class=thSubject>Tiêu đề</th>\r\n" +
                   "                    <th class=thStatus>Trạng thái</th>\r\n" +
                   "                    <th class=thDate>Ngày tạo</th>\r\n" +
                   "                    <th class=thFunc></th>\r\n" +
                   "                </tr>\r\n";
                for (int iIndex = 0; iIndex < CmsData.Length; iIndex++)
                {
                    string ReleaseButton = 
                        "<input type=button class=button value=\"Phát hành\" onclick=\"javascript:ClientPublic('"+CmsData[iIndex].DataId+"');\">";
                    if (CmsData[iIndex].IsPublic == 1)
                    {
                        ReleaseButton =
                            "<input type=button class=button value=\"Ngưng phát hành\" onclick=\"javascript:ClientUnPublic('" + CmsData[iIndex].DataId + "');\">";
                    }

                    string SubMenuButton = "";
                    //if (OGroupData.AllowSub==1)
                    //{
                    //    SubMenuButton=
                    //        "<input style=\"width:80px;font-size:12px;\" type=button class=button value=\"Dữ liệu con\" onclick=\"javascript:window.open('InputData.aspx?gid=" + OGroupData.GroupDataId + "&parent=" + CmsData[iIndex].DataId + "','_self');\">";
                    //}
                    //<span class=CssDataAlias>"+CmsData[iIndex].DataAlias+"</span>
                    string DisplayInfo = "<span class=NewsSubject><a href=\"PreviewCmsData.aspx?gid="+CmsData[iIndex].frkGroupDataId+"&CmsDataId="+CmsData[iIndex].DataId+"\">" + CmsData[iIndex].Subject + "</a></span><br><span class=CssImageInclude>" + (CmsData[iIndex].Avatar.Length > 0 ? "<a href=\"" + CmsData[iIndex].GetAvatarUrl(SiteId,WebConfig.HttpDataRoot(OSiteParam)) + "\" target=\"_blank\">Có ảnh kèm theo</a>" : "") + "</span><br><span class=CssImageInclude>" + (CmsData[iIndex].AttachDoc.Length > 0 ? "<a href=\"" + CmsData[iIndex].GetAttachDocUrl(SiteId,WebConfig.HttpDataRoot(OSiteParam)) + "\" target=\"_blank\">Có tài liệu kèm theo</a>" : "") + "</span><div class=CssItemDesc>" + FunctionUtilities.CutText(CmsData[iIndex].Description, 15) + "</div>\r\n";
                    //string DisplayInfo = "";
                    if (CmsData[iIndex].DataType.Equals("images") || CmsData[iIndex].DataType.Equals("album"))
                    {
                        string ImageUrl = CmsData[iIndex].GetSmallAvatarUrl(SiteId,WebConfig.HttpDataRoot(OSiteParam));
                        if (CmsData[iIndex].HasImage(SiteId,WebConfig.DataPathRoot(OSiteParam)))
                        {
                            ImageUrl = ConvertUrl(ImageUrl);
                            DisplayInfo = "<img class=CssImageThumb src=\"" + ImageUrl + "\">";
                        }
                        else
                        {
                            DisplayInfo = "Chưa có ảnh đại diện";
                        }
                    }

                    string AttachDocText = "Ảnh";
                    Html +=
                       "                <tr>\r\n" +
                       "                    <td>" + (iIndex + 1) + "</td>\r\n" +
                       //"                    <td style=\"width:100px;\">" + CmsData[iIndex].DataAlias + "</td>\r\n" +
                       "                    <td>\r\n" +
                                DisplayInfo+
                       "                    </td>\r\n" +
                       "                    <td><div id=\"divStatusText"+CmsData[iIndex].DataId+"\">" + (CmsData[iIndex].IsPublic == 1 ? "Đã phát hành" : "Chờ phát hành") + "</div><div id=\"divButton"+CmsData[iIndex].DataId+"\">"+ReleaseButton+"</div></td>\r\n" +
                       "                    <td style=\"width:120px;\">" + CmsData[iIndex].EntryDate.ToString("dd/MM/yyyy HH:mm") + "</td>\r\n" +
                       "                    <td>\r\n"+
                       "                        <input style=\"width:50px;font-size:10px;\" type=button class=button value=\"Sửa\" onclick=\"javascript:ClientUpdate('" + GroupDataId + "','" + CmsData[iIndex].DataId + "');\">\r\n" +
                       "                        <input style=\"width:50px;font-size:10px;\" type=button class=button value=\"Xóa\" onclick=\"javascript:ClientDelete('" + GroupDataId + "','" + CmsData[iIndex].DataId + "');\">\r\n" +
                       //"                        <input style=\"width:50px;font-size:10px;\" type=button class=button value=\""+AttachDocText+"\" onclick=\"javascript:ClientChangeAvatar('" + GroupDataId + "','" + CmsData[iIndex].DataId + "');\">\r\n" +
                       SubMenuButton+
                       //"                        <input style=\"width:50px;font-size:10px;\" type=button class=button value=\"Tài liệu\" onclick=\"javascript:ClientAttachDoc('" + GroupDataId + "','" + CmsData[iIndex].DataId + "');\">\r\n" +
                       "                    </td>\r\n"+
                       "                </tr>\r\n";
                }
                Html +=
                   "    </table>\r\n";
                   
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


        //public static string GetSelect(string SiteId, string FileName, string ComboboxId,string FocusId)
        //{
        //    try
        //    {
        //        SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
        //        string Xml = OSiteParam.PathRoot + "\\Admin\\XmlData\\News\\" + FileName;
        //        DataSet ds = new DataSet();
        //        ds.ReadXml(Xml);
        //        string SelectData =
        //            " <select id=\"" + ComboboxId + "\" class=drplist>\r\n" +
        //            "   <option value=\"\"></option>\r\n";
        //        for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
        //        {
        //            string Id = (string)ds.Tables[0].Rows[iIndex]["Id"];
        //            string Name = (string)ds.Tables[0].Rows[iIndex]["Name"];
        //            if (FocusId.Equals(Id))
        //            {
        //                SelectData += "<option selected value=\"" + Id + "\">" + Name + "</option>\r\n";
        //            }
        //            else
        //            {
        //                SelectData += "<option value=\"" + Id + "\">" + Name + "</option>\r\n";
        //            }
        //        }
        //        SelectData += " </select>\r\n";
        //        return SelectData;
        //    }
        //    catch
        //    {
        //        return "";
        //    }
        //}



        //[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        //public static AjaxOut BuildCategory(string SiteId,string TreeViewId)
        //{
        //    AjaxOut OAjaxOut = new AjaxOut();
        //    try
        //    {
        //        SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
        //        string XmlFile = OSiteParam.PathRoot + "\\admin\\xmldata\\news\\Category\\95.xml";
        //        DataSet ds = new DataSet();
        //        ds.ReadXml(XmlFile);
        //        DataView dv = new DataView(ds.Tables[0], "ParentId='0'", "", DataViewRowState.CurrentRows);
        //        string Html =
        //            "<div class=CssListField>\r\n" +
        //            "<ul id=\""+TreeViewId+"\" class=\"TreeView\">\r\n";
        //        for (int iIndex = 0; iIndex < dv.Count; iIndex++)
        //        {
        //            string Id = dv[iIndex]["Id"].ToString();
        //            string Name = dv[iIndex]["Name"].ToString();
        //            DataView dvSub = new DataView(ds.Tables[0], "ParentId='" + Id + "'", "", DataViewRowState.CurrentRows);
        //            if (dvSub.Count > 0)
        //            {
        //                Html += " <li id=\"" + Id + "\" class=\"Collapsed\">\r\n" +
        //                            "<a href=\"javascript:ProcessExpandCollapse('" + Id + "');\"><span id=\"spanMainFieldName" + Id + "\">" + Name + "</span></a>\r\n" +
        //                                "<input type=hidden value=\"0\" id=\"txtReadSubField" + Id + "\"><ul id=\"ulSubField" + Id + "\">\r\n" +
        //                                    ServerSideReadingSubField(SiteId, Id).HtmlContent +
        //                                "</ul>\r\n" +
        //                            "</li>\r\n";
        //            }
        //            else
        //            {
        //                Html += " <li id=\"" + Id + "\" class=\"Collapsed\">\r\n" +
        //                        "<input type=checkbox class=checkbox onchange=\"javascript:ProcessCheckCategory('" + Id + "','')\" id=\"chk" + Id + "\" style=\"margin-right:4px;\"><span id=\"spanMainFieldName" + Id + "\">" + Name + "</span><input id=\"chkHot" + Id + "\" style=\"margin-left:5px;\" type=checkbox class=checkbox onchange=\"javascript:ProcessHotCategory('" + Id + "');\">Nóng chuyên mục\r\n" +
        //                                "<input type=hidden value=\"0\" id=\"txtReadSubField" + Id + "\"><ul id=\"ulSubField" + Id + "\">\r\n" +
                                    
        //                                "</ul>\r\n" +
        //                            "</li>\r\n";
        //            }
        //        }
        //        Html += "</ul>\r\n" +
        //              "</div>\r\n";
        //        OAjaxOut.HtmlContent = Html;
        //    }
        //    catch (Exception ex)
        //    {
        //        OAjaxOut.Error = true;
        //        OAjaxOut.InfoMessage = ex.Message.ToString();
        //        OAjaxOut.HtmlContent = ex.Message.ToString();
        //    }

        //    return OAjaxOut;
        //}

        //[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        //public static AjaxOut ServerSideReadingSubField(string SiteId, string CategoryId)
        //{
        //    AjaxOut OAjaxOut = new AjaxOut();
        //    try
        //    {
        //        SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
        //        string XmlFile = OSiteParam.PathRoot + "\\admin\\xmldata\\news\\Category\\95.xml";
        //        DataSet ds = new DataSet();
        //        ds.ReadXml(XmlFile);
        //        DataView dv = new DataView(ds.Tables[0], "ParentId='"+CategoryId+"'", "", DataViewRowState.CurrentRows);
     
        //        string Html = "";
        //        for (int jIndex = 0; jIndex < dv.Count; jIndex++)
        //        {
        //            string Id = dv[jIndex]["Id"].ToString();
        //            string Name = dv[jIndex]["Name"].ToString();

        //            Html += " <li class=liSubTreeViewItem>\r\n"+
        //                    "       <input type=checkbox class=checkbox onchange=\"javascript:ProcessCheckCategory('" + Id + "','')\" id=\"chk" + Id + "\" style=\"margin-right:4px;\"><span id=\"spanMainFieldName" + Id + "\">" + Name + "</span><input id=\"chkHot" + Id + "\" style=\"margin-left:5px;\" type=checkbox class=checkbox onchange=\"javascript:ProcessHotCategory('" + Id + "');\">Nóng chuyên mục\r\n" +
        //                    " </li>\r\n";
        //        }
        //        OAjaxOut.RetNumber = dv.Count;
        //        OAjaxOut.HtmlContent = Html;
        //    }
        //    catch (Exception ex)
        //    {
        //        OAjaxOut.Error = true;
        //        OAjaxOut.InfoMessage = ex.Message.ToString();
        //        OAjaxOut.HtmlContent = ex.Message.ToString();
        //    }

        //    return OAjaxOut;
        //}




        //[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        //public static AjaxOut DrawAddForm(string SiteId, string GroupDataId)
        //{
        //    AjaxOut OAjaxOut = new AjaxOut();
        //    try
        //    {
        //        WebSessionUtility.CheckSessionTimeOut();
        //        GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(SiteId, GroupDataId);
        //        string StyleDisp = " style=\"display:none;\"";
        //        if (OGroupData.ShowBody)
        //        {
        //            StyleDisp = "";
        //        }

        //        string BackScript = "javascript:window.open('InputData.aspx?gid=" + OGroupData.GroupDataId + "','_self');";
        //        if (OGroupData.frkDataTypeId.Equals("document"))
        //        {
        //            BackScript = "javascript:window.open('DocumentInputData.aspx?gid=" + OGroupData.GroupDataId + "','_self');";
        //        }


        //        string UploadHandler = "CmsUploadHandler.ashx";
        //        if (OGroupData.frkDataTypeId.Equals("document"))
        //        {
        //            UploadHandler = "CmsUploadAttachFileHandler.ashx";
        //        }
        //        string NewDataId = System.Guid.NewGuid().ToString();
        //        string Html =
        //             "<script language=javascript>\r\n " +

        //            "  function ProcessExpandCollapse(Id)\r\n" +
        //            "  {\r\n" +
        //            "     if(document.getElementById(Id).className=='Collapsed')\r\n" +
        //            "     {\r\n" +
        //            //"         if(document.getElementById('txtReadSubField'+Id).value=='0')\r\n" +
        //            //"         {\r\n" +
        //            //"             AjaxOut = Portal.Library.Render.FieldRenderBll.ServerSideReadingSubField(SiteId,Id).value;\r\n" +
        //            //"             document.getElementById('ulSubField'+Id).innerHTML=AjaxOut.HtmlContent;\r\n" +
        //            //"             document.getElementById('txtReadSubField'+Id).value=AjaxOut.RetNumber;\r\n" +
        //            //"         }\r\n" +
        //            "         document.getElementById(Id).className='Expanded';\r\n" +
        //            "     }\r\n" +
        //            "     else\r\n" +
        //            "     {\r\n" +
        //            "         document.getElementById(Id).className='Collapsed';\r\n" +
        //            "     }\r\n" +
        //            "  }\r\n" +

        //             " function CallSaveAddData()\r\n" +
        //             " {\r\n" +
        //             "      document.getElementById('divCallSaveAddDataProcessing').innerHTML='Tiến hành cập nhật và đánh index tìm kiếm...';\r\n" +
        //             "      setTimeout('RealCallSaveAddData()',10);\r\n" +
        //             " }\r\n" +

        //             "  function RealCallSaveAddData()\r\n" +
        //             "  {\r\n" +
        //             "      SiteId='" + SiteId + "';\r\n" +
        //             "      GroupDataId='" + GroupDataId + "';\r\n" +
        //             "      DataId=document.getElementById('txtDataId').value;\r\n"+
        //             "      Alias = document.getElementById('txtAlias').value;\r\n" +
        //             "      Subject = document.getElementById('txtSubject').value;\r\n" +
        //             "      Description = document.getElementById('txtDescription').value;\r\n" +
        //             "      Body = '';\r\n" +
        //             "      if(FCKeditorAPI!=null){\r\n" +
        //             "          oEditor = FCKeditorAPI.GetInstance('FCKeditorBody');\r\n" +
        //             "          Body= oEditor.GetXHTML( true ); \r\n" +
        //             "      }\r\n" +
        //             "      Source = document.getElementById('txtSource').value;\r\n" +
        //             "      Url = document.getElementById('txtUrl').value;\r\n" +
        //             "      Target = document.getElementById('txtTarget').value;\r\n" +
        //             "      UploadFile=document.getElementById('txtUploadFile').value;\r\n" +
        //             "      SortIndex=document.getElementById('txtSortIndex').value;\r\n" +
        //             "      ParentDataId=document.getElementById('txtParentDataId').value;\r\n" +

        //             "      DocType='';\r\n"+
        //             "      if(document.getElementById('drpSelectDocType')!=null)\r\n"+
        //             "      {\r\n"+
        //             "          DocType=document.getElementById('drpSelectDocType').value;\r\n"+
        //             "      }\r\n"+

        //             "      DocField='';\r\n" +
        //             "      if(document.getElementById('drpSelectDocField')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocField=document.getElementById('drpSelectDocField').value;\r\n" +
        //             "      }\r\n" +
                     
        //             "      DocReleaseFrom='';\r\n" +
        //             "      if(document.getElementById('drpSelectDocReleaseFrom')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocReleaseFrom=document.getElementById('drpSelectDocReleaseFrom').value;\r\n" +
        //             "      }\r\n" +
        //             "      DocSigner='';\r\n" +
        //             "      if(document.getElementById('drpSelectDocSigner')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocSigner=document.getElementById('drpSelectDocSigner').value;\r\n" +
        //             "      }\r\n" +

        //             "      DocStatus='';\r\n" +
        //             "      if(document.getElementById('drpSelectDocStatus')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocStatus=document.getElementById('drpSelectDocStatus').value;\r\n" +
        //             "      }\r\n" +

        //             "      ReleaseDate='';\r\n" +
        //             "      if(document.getElementById('txtReleaseDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          ReleaseDate=document.getElementById('txtReleaseDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      EffectedDate='';\r\n" +
        //             "      if(document.getElementById('txtEffectedDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          EffectedDate=document.getElementById('txtEffectedDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      EndEffectedDate='';\r\n" +
        //             "      if(document.getElementById('txtEndEffectedDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          EndEffectedDate=document.getElementById('txtEndEffectedDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      SignDate='';\r\n" +
        //             "      if(document.getElementById('txtSignDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          SignDate=document.getElementById('txtSignDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      ReplaceDoc='';\r\n" +
        //             "      if(document.getElementById('txtReplaceDoc')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          ReplaceDoc=document.getElementById('txtReplaceDoc').value;\r\n" +
        //             "      }\r\n" +

        //             "      ModifyDoc='';\r\n" +
        //             "      if(document.getElementById('txtModifyDoc')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          ModifyDoc=document.getElementById('txtModifyDoc').value;\r\n" +
        //             "      }\r\n" +

        //             "      VoteType='';\r\n" +
        //             "      if(document.getElementById('drpSelectVoteType')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          VoteType=document.getElementById('drpSelectVoteType').value;\r\n" +
        //             "      }\r\n" +

        //             "      IsNew = document.getElementById('drpSelectIsNew').value;\r\n"+
        //             "      Searchable=0;\r\n"+
        //             "      if(document.getElementById('drpSelectSearchable')!=null)\r\n"+
        //             "      {\r\n"+
        //             "          Searchable=document.getElementById('drpSelectSearchable').value;\r\n" +
        //             "      }\r\n"+

        //             "      AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideAdd(SiteId, DataId, GroupDataId, ParentDataId, Alias, Subject, Description, Body, Source, Url, Target, UploadFile, SortIndex, DocType,DocField, DocReleaseFrom,DocSigner,DocStatus,SignDate, ReleaseDate,EffectedDate,EndEffectedDate,ReplaceDoc,ModifyDoc, VoteType, IsNew, Searchable).value;\r\n" +
        //             "      document.getElementById('divCallSaveAddDataProcessing').innerHTML='';\r\n" +
        //             "      if(AjaxOut.Error)\r\n" +
        //             "      {\r\n" +
        //             "          alert(AjaxOut.InfoMessage);\r\n" +
        //             "          return;\r\n" +
        //             "      }\r\n" +
        //             "      if(AjaxOut.RetUrl!='')\r\n"+
        //             "      {\r\n"+
        //             "          window.open(AjaxOut.RetUrl,'_self');\r\n" +
        //             "      }\r\n"+
        //             "      else\r\n"+
        //             "      {\r\n"+
        //             "          document.getElementById('divListForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
        //             "          ClientBack();\r\n" +
        //             "      }\r\n"+
        //             "  }\r\n" +


        //             "function fileSelected() {\r\n" +
        //             "    var file = document.getElementById('fileToUpload').files[0];\r\n" +
        //             "    if (file) {\r\n" +
        //             "        var fileSize = 0;\r\n" +
        //             "        if (file.size > 1024 * 1024)\r\n" +
        //             "            fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';\r\n" +
        //             "        else\r\n" +
        //             "            fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';\r\n" +
        //             "        document.getElementById('fileName').innerHTML = 'Tên tệp: ' + file.name;\r\n" +
        //             "        document.getElementById('fileSize').innerHTML = 'Kích cỡ: ' + fileSize;\r\n" +
        //             "        document.getElementById('fileType').innerHTML = 'Loại tệp: ' + file.type;\r\n" +
        //             "    }\r\n" +
        //             "}\r\n" +

        //             "function uploadFile() {\r\n" +
        //             "    if(document.getElementById('fileToUpload').value==''){\r\n" +
        //             "       CallSaveAddData();\r\n" +
        //             "       return;\r\n" +
        //             "   }\r\n" +
        //             "    DataId=document.getElementById('txtDataId').value;\r\n"+
        //             "    var fd = new FormData();\r\n" +
        //             "    fd.append(\"fileToUpload\", document.getElementById('fileToUpload').files[0]);\r\n" +
        //             "    var xhr = new XMLHttpRequest();\r\n" +
        //             "    xhr.upload.addEventListener(\"progress\", uploadProgress, false);\r\n" +
        //             "    xhr.addEventListener(\"load\", uploadComplete, false);\r\n" +
        //             "    xhr.addEventListener(\"error\", uploadFailed, false);\r\n" +
        //             "    xhr.addEventListener(\"abort\", uploadCanceled, false);\r\n" +
        //             "    xhr.open(\"POST\", \"" + UploadHandler + "?sid=" + SiteId + "&uni=" + WebSessionUtility.GetCurrentLoginUser().AssetCode + "&gid=" + GroupDataId + "&dataid="+NewDataId+"\");\r\n" +
        //             "    xhr.send(fd);\r\n" +
        //             "}\r\n" +

        //             "function uploadProgress(evt) {\r\n" +
        //             "    if (evt.lengthComputable) {\r\n" +
        //             "    }\r\n" +
        //             "    else {\r\n" +
        //             "        document.getElementById('progressNumber').innerHTML = 'Không tính toán được thời gian';\r\n" +
        //             "    }\r\n" +
        //             "}\r\n" +



        //             "function uploadComplete(evt) {\r\n" +
        //             "    /* This event is raised when the server send back a response */\r\n" +
        //             "  if(evt.target.responseText.indexOf('ERROR')!=-1)\r\n"+
        //             "  {\r\n"+
        //             "      alert(evt.target.responseText.substring(6));\r\n"+
        //             "      return;\r\n"+
        //             "  }\r\n"+
        //             "    document.getElementById('txtUploadFile').value=evt.target.responseText;\r\n" +
        //             "    //doan nay chay upload vao day...\r\n" +
        //             "    CallSaveAddData();\r\n" +
        //             "   }\r\n" +

        //               "function uploadFailed(evt) {\r\n" +
        //             "       alert(\"Lỗi khi tải tệp dữ liệu lên máy chủ.\");\r\n" +
        //             "   }\r\n" +

        //             "   function uploadCanceled(evt) {\r\n" +
        //             "        alert(\"Người dùng hủy bỏ tải lên máy chủ hoặc mất kết nối với máy chủ.\");\r\n" +
        //             "   }\r\n" +


        //           "  </script>\r\n";

        //        string CodeCaption = "Mã";
        //        string DescCaption = "Mô tả";
        //        string AttachCaption = "Ảnh gắn kèm";
        //        if (OGroupData.frkDataTypeId.Equals("document"))
        //        {
        //            CodeCaption = "Số văn bản";
        //            DescCaption = "Mô tả / trích yếu";
        //            AttachCaption="Tệp toàn văn";
        //        }
        //        string SelectVoteType = "";
        //        if (OGroupData.frkDataTypeId.Equals("vote"))
        //        {
        //            SelectVoteType = " <select id=drpSelectVoteType>\r\n" +
        //                             "      <option value=\"one\">Chỉ chọn 1 phương án</option>\r\n" +
        //                             "      <option value=\"two\">Chọn nhiều phương án</option>\r\n" +
        //                             "      <option value=\"text\">Nhập text</option>\r\n" +
        //                             " </select>\r\n";
        //        }

        //        string SelectIsNew = " <select id=\"drpSelectIsNew\">\r\n" +
        //             "      <option value=\"0\">Tài liệu bình thường</option>\r\n" +
        //             "      <option value=\"1\" selected>Tài liệu mới</option>\r\n" +
        //             " </select>\r\n";


        //        string SelectSearchable =
        //            " <select id=\"drpSelectSearchable\">\r\n" +
        //            "      <option value=\"0\">Không tìm kiếm toàn văn được</option>\r\n" +
        //            "      <option value=\"1\" selected>Tìm kiếm toàn văn được</option>\r\n" +
        //            " </select>\r\n";

        //        SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
        //        string ButtonRoot = WebConfig.GetButtonIconRoot(OSiteParam);
        //        Html+=
        //           " <input id=txtAddCheckedCategory type=hidden style=\"width:400px;\">\r\n" +
        //           " <input id=txtAddCheckedHotCategory type=hidden style=\"width:400px;\">\r\n" +
        //           " <div class=DatabaseFunction>\r\n" +
        //           "        <ul>\r\n" +
        //           "            <li onclick=\"javascript:uploadFile();\"><img class=image src=\""+ButtonRoot+"/Save.png\"><div>Ghi lại</div></li>\r\n" +
        //           "            <li onclick=\"" + BackScript + "\"><img class=image src=\""+ButtonRoot+"/back.png\"><div>Quay lại</div></li>\r\n" +
        //           "        </ul>\r\n" +
        //           "  </div>\r\n" +
        //           "<div class=CssFormSaveUpdate>\r\n" + 
        //           "  <input type=hidden id=txtDataId value=\""+NewDataId+"\">\r\n"+
        //           "  <h3>Thêm mới dữ liệu</h3>\r\n" +
        //           "  <div id=divCallSaveAddDataProcessing class=CssProcessing></div>\r\n"+
        //           "  <table>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>"+CodeCaption+":</td>\r\n" +
        //           "        <td class=c2><input id=txtAlias value=\"" + System.Guid.NewGuid().ToString().Substring(0, 8) + "\" class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Tiêu đề:</td>\r\n" +
        //           "        <td class=c2><input id=txtSubject class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Phụ đề:</td>\r\n" +
        //           "        <td class=c2><input id=txtOtherSubject class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1 style=\"vertical-align:top;\">"+DescCaption+":</td>\r\n" +
        //           "        <td class=c2>\r\n"+
        //            "               <textarea type=hidden id=\"FCKeditorSapo\" name=\"FCKeditorSapo\"></textarea>\r\n" +
        //            "               <script type=\"text/javascript\" src=\"/fckeditor/fckeditor.js\"></script>\r\n" +
        //            "               <script type=\"text/javascript\">\r\n" +
        //            "                   var oFCKeditor = new FCKeditor('FCKeditorSapo');\r\n" +
        //            "                   oFCKeditor.BasePath = \"/fckeditor/\";\r\n" +
        //            "                   oFCKeditor.Height = \"300\";\r\n" +
        //            "                   oFCKeditor.ReplaceTextarea();\r\n" +
        //            "               </script>\r\n" +
        //           "        </td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr " + StyleDisp + ">\r\n" +
        //           "        <td class=c1 style=\"vertical-align:top;\">Nội dung:</td>\r\n" +
        //           "        <td class=c2>\r\n" +
        //           "                <textarea type=hidden id=\"FCKeditorBody\" name=\"FCKeditorBody\"></textarea>\r\n" +
        //            "               <script type=\"text/javascript\" src=\"/fckeditor/fckeditor.js\"></script>\r\n" +
        //            "               <script type=\"text/javascript\">\r\n" +
        //            "                   var oFCKeditor = new FCKeditor('FCKeditorBody');\r\n" +
        //            "                   oFCKeditor.BasePath = \"/fckeditor/\";\r\n" +
        //            "                   oFCKeditor.Height = \"600\";\r\n" +
        //            "                   oFCKeditor.ReplaceTextarea();\r\n" +
        //            "               </script>\r\n" +
        //           "        </td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Nguồn / tác giả:</td>\r\n" +
        //           "        <td class=c2><input id=txtSource class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +

        //           "    <tr>\r\n" +
        //           "        <td class=c1>Chuyên mục:</td>\r\n" +
        //           "        <td class=c2>" + BuildCategory(SiteId,"AddTreeView").HtmlContent + "</td>\r\n" +
        //           "    </tr>\r\n" +

        //           "    <tr>\r\n" +
        //           "        <td class=c1>Url:</td>\r\n" +
        //           "        <td class=c2><input id=txtUrl class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Ngày tạo:</td>\r\n" +
        //           "        <td class=c2><input id=txtEntryDate class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Ngày hết hạn:</td>\r\n" +
        //           "        <td class=c2><input id=txtExpiredDate class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Loại tin bài:</td>\r\n" +
        //           "        <td class=c2>"+GetSelect(SiteId,"Portal_vi_NewsType.xml","drpSelectNewsType","")+"</td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Định mức ảnh mới:</td>\r\n" +
        //           "        <td class=c2>" + GetSelect(SiteId, "Portal_vi_ImageLevel.xml", "drpSelectImageLevel", "") + "</td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Số ảnh khai thác:</td>\r\n" +
        //           "        <td class=c2><input id=\"txtImageCount\"></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Thuộc sự kiện:</td>\r\n" +
        //           "        <td class=c2>" + GetSelect(SiteId, "Portal_en_Event.xml", "drpSelectEvent", "") + "</td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Định mức ảnh khai thác:</td>\r\n" +
        //           "        <td class=c2>" + GetSelect(SiteId, "Portal_vi_Exploitation.xml", "drpSelectExploitation", "") + "</td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Mức tin bài:</td>\r\n" +
        //           "        <td class=c2>" + GetSelect(SiteId, "Portal_vi_NewsLevel.xml", "drpSelectNewsType", "") + "</td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1></td>\r\n" +
        //           "        <td class=c2><div class=CssDivCheckBox>Là tin nổi bật <input type=checkbox class=checkbox>Hiện tên tác giả <input type=checkbox class=checkbox>Quảng cáo doanh nghiệp <input type=checkbox class=checkbox></div></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Từ khóa:</td>\r\n" +
        //           "        <td class=c2><input id=txtKeyword type=textbox class=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Mã cuộc bình chọn:</td>\r\n" +
        //           "        <td class=c2><input id=txtSurveyCode type=textbox class=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Ghi chú:</td>\r\n" +
        //           "        <td class=c2><textarea type=textarea class=textarea id=txtNote></textarea></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Kiểu link:</td>\r\n" +
        //           "        <td class=c2><input id=txtTarget class=textbox type=textbox value=\"_self\"></td>\r\n" +
        //           "    </tr>\r\n";
        //        if (OGroupData.frkDataTypeId.Equals("document"))
        //        {
        //            string SelectDocumentType =
        //                "<select id=drpSelectDocType class=drplist>\r\n";
        //            DocTypeCls[] DocTypes = DocTypeProcessBll.ReadingDocType(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocTypes.Length; iIndex++)
        //            {
        //                SelectDocumentType += "   <option value=\"" + DocTypes[iIndex].DocTypeId + "\">" + DocTypes[iIndex].DocTypeName + "</option>\r\n";
        //            }
        //            SelectDocumentType += "</select>\r\n";


        //            string SelectDocField =
        //              "<select id=drpSelectDocField class=drplist>\r\n";
        //            DocFieldCls[] DocFields = DocFieldProcessBll.ReadingDocField(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocFields.Length; iIndex++)
        //            {
        //                SelectDocField += "   <option value=\"" + DocFields[iIndex].DocFieldId + "\">" + DocFields[iIndex].DocFieldName + "</option>\r\n";
        //            }
        //            SelectDocField += "</select>\r\n";

        //            string SelectDocReleaseFrom =
        //                "<select id=drpSelectDocReleaseFrom class=drplist>\r\n";
        //            DocReleaseFromCls[] DocReleaseFroms = DocReleaseFromProcessBll.ReadingDocReleaseFrom(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocReleaseFroms.Length; iIndex++)
        //            {
        //                SelectDocReleaseFrom += "   <option value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + DocReleaseFroms[iIndex].DocReleaseFromName + "</option>\r\n";
        //            }
        //            SelectDocReleaseFrom += "</select>\r\n";

        //            string SelectDocSigner =
        //              "<select id=drpSelectDocSigner class=drplist>\r\n";
        //            DocSignerCls[] DocSigners = DocSignerProcessBll.ReadingDocSigner(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocSigners.Length; iIndex++)
        //            {
        //                SelectDocSigner += "   <option value=\"" + DocSigners[iIndex].DocSignerId + "\">" + DocSigners[iIndex].DocSignerName + "</option>\r\n";
        //            }
        //            SelectDocSigner += "</select>\r\n";

        //            string SelectStatus =
        //                "<select id=drpSelectDocStatus class=drplist>\r\n" +
        //                "   <option value=\"0\">Hết hiệu lực</option>\r\n" +
        //                "   <option value=\"1\">Có hiệu lực</option>\r\n" +
        //                "</select>\r\n";

        //            Html +=
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Loại văn bản:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocumentType + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Cơ quan ban hành:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocReleaseFrom + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Lĩnh vực:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocField + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Người ký:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocSigner + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Trạng thái:</td>\r\n" +
        //             "        <td class=c2>" + SelectStatus + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày ký:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtSignDate") + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày ban hành:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtReleaseDate") + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày hiệu lực:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtEffectedDate") + "</td>\r\n" +
        //             "    </tr>\r\n"+
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày hết hiệu lực:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtEndEffectedDate") + "</td>\r\n" +
        //             "    </tr>\r\n"+
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Tìm kiếm toàn văn:</td>\r\n" +
        //             "        <td class=c2>" + SelectSearchable + "</td>\r\n" +
        //             "    </tr>\r\n";
        //        }

        //        if (OGroupData.frkDataTypeId.Equals("vote"))
        //        {
        //            Html +=
        //                "    <tr>\r\n" +
        //                "        <td class=c1>Loại đánh giá:</td>\r\n" +
        //                "        <td class=c2>" + SelectVoteType + "</td>\r\n" +
        //                "    </tr>\r\n";
        //        }
        //        Html +=
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Thứ tự:</td>\r\n" +
        //           "        <td class=c2><input id=txtSortIndex class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Trạng thái:</td>\r\n" +
        //           "        <td class=c2>" + SelectIsNew + "</td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "         <td class=c1>" + AttachCaption + ":</td>\r\n" +
        //           "         <td><input type=hidden id=\"txtUploadFile\"><input type=\"file\" name=\"fileToUpload[]\" id=\"fileToUpload\" onchange=\"fileSelected();\" /></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "       <tr>\r\n" +
        //            "           <td></td>\r\n" +
        //            "           <td>\r\n" +
        //            "               <div id=\"progressNumber\"></div>\r\n" +
        //            "               <div id=\"fileName\">\r\n" +
        //            "               </div>\r\n" +
        //            "               <div id=\"fileSize\">\r\n" +
        //            "               </div>\r\n" +
        //            "               <div id=\"fileType\">\r\n" +
        //            "               </div>\r\n" +
        //            "           </td>\r\n" +
        //            "       </tr>\r\n" +

        //           //"    <tr>\r\n" +
        //            //"        <td class=c1></td>\r\n" +
        //            //"        <td class=c2><input type=button class=button value=\"Chấp nhận\" onclick=\"javascript:uploadFile();\"><input type=button class=button value=\"Quay lại\" onclick=\""+BackScript+"\"></td>\r\n" +
        //            //"    </tr>\r\n" +
        //           "  </table>\r\n" +
        //           "</div>\r\n";
                   

        //        OAjaxOut.HtmlContent = Html;
        //    }
        //    catch (Exception ex)
        //    {
        //        OAjaxOut.InfoMessage = ex.Message.ToString();
        //        OAjaxOut.HtmlContent = ex.Message.ToString();
        //        OAjaxOut.Error = true;
        //    }

        //    return OAjaxOut;
        //}


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawChangeAvatarForm(string SiteId, string GroupDataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonUrl = WebConfig.GetButtonIconRoot(OSiteParam);
                string Html =
                     "<script language=javascript>\r\n " +
                     "function fileSelectedChangeAvatar() {\r\n" +
                     "    var file = document.getElementById('fileToUploadChangeAvatar').files[0];\r\n" +
                     "    if (file) {\r\n" +
                     "        var fileSize = 0;\r\n" +
                     "        if (file.size > 1024 * 1024)\r\n" +
                     "            fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';\r\n" +
                     "        else\r\n" +
                     "            fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';\r\n" +
                     "        document.getElementById('fileNameChangeAvatar').innerHTML = 'Tên tệp: ' + file.name;\r\n" +
                     "        document.getElementById('fileSizeChangeAvatar').innerHTML = 'Kích cỡ: ' + fileSize;\r\n" +
                     "        document.getElementById('fileTypeChangeAvatar').innerHTML = 'Loại tệp: ' + file.type;\r\n" +
                     "    }\r\n" +
                     "}\r\n" +

                     "function uploadFileChangeAvatar() {\r\n" +
                     "    if(document.getElementById('fileToUploadChangeAvatar').value==''){\r\n" +
                     "       document.getElementById('txtUploadFileChangeAvatar').value='';\r\n" +
                     "       CallSaveAvatar();\r\n" +
                     "       return;\r\n" +
                     "   }\r\n" +
                     "    var fd = new FormData();\r\n" +
                     "    fd.append(\"fileToUpload\", document.getElementById('fileToUploadChangeAvatar').files[0]);\r\n" +
                     "    var xhr = new XMLHttpRequest();\r\n" +
                     "    xhr.upload.addEventListener(\"progress\", uploadProgressChangeAvatar, false);\r\n" +
                     "    xhr.addEventListener(\"load\", uploadCompleteChangeAvatar, false);\r\n" +
                     "    xhr.addEventListener(\"error\", uploadFailedChangeAvatar, false);\r\n" +
                     "    xhr.addEventListener(\"abort\", uploadCanceledChangeAvatar, false);\r\n" +
                     "    xhr.open(\"POST\", \"CmsUploadHandler.ashx?sid=" + SiteId + "&uni=" + WebSessionUtility.GetCurrentLoginUser().AssetCode + "&gid=" + GroupDataId + "\");\r\n" +
                     "    xhr.send(fd);\r\n" +
                     "}\r\n" +

                     "function uploadProgressChangeAvatar(evt) {\r\n" +
                     "    if (evt.lengthComputable) {\r\n" +
                     "    }\r\n" +
                     "    else {\r\n" +
                     "        document.getElementById('progressNumberChangeAvatar').innerHTML = 'Không tính toán được thời gian';\r\n" +
                     "    }\r\n" +
                     "}\r\n" +

                     " function CallSaveAvatar()\r\n" +
                     " {\r\n" +
                     "      document.getElementById('divCallSaveAvatarProcessing').innerHTML='Tiến hành cập nhật và đánh index tìm kiếm...';\r\n" +
                     "      setTimeout('RealCallSaveAvatar()',10);\r\n" +
                     " }\r\n" +

                     " function RealCallSaveAvatar()\r\n" +
                     " {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      DataId = document.getElementById('txtChangeAvatarUpdateId').value;\r\n" +
                     "      uploadFile = document.getElementById('txtUploadFileChangeAvatar').value;\r\n" +
                     "      ParentDataId=document.getElementById('txtParentDataId').value;\r\n" +
                     "      AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideSaveAvatar(SiteId,'" + GroupDataId + "',ParentDataId, DataId, uploadFile).value;\r\n" +
                     "      document.getElementById('divCallSaveAvatarProcessing').innerHTML='';\r\n" +
                     "      if(AjaxOut.Error)\r\n" +
                     "      {\r\n" +
                     "          alert(AjaxOut.InfoMessage);\r\n" +
                     "          return;\r\n" +
                     "      }\r\n" +
                     "      if(AjaxOut.RetUrl!='')\r\n" +
                     "      {\r\n" +
                     "          window.open(AjaxOut.RetUrl,'_self');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          ClientBack();\r\n" +
                     "      }\r\n" +
                     " }\r\n" +


                     "function uploadCompleteChangeAvatar(evt) {\r\n" +
                     "    /* This event is raised when the server send back a response */\r\n" +
                     "    document.getElementById('txtUploadFileChangeAvatar').value=evt.target.responseText;\r\n" +
                     "    //doan nay chay upload vao day...\r\n" +
                     "    CallSaveAvatar();\r\n" +
                     "   }\r\n  " +

                       "function uploadFailedChangeAvatar(evt) {\r\n" +
                     "       alert(\"Lỗi khi tải tệp dữ liệu lên máy chủ.\");\r\n" +
                     "   }\r\n" +

                     "   function uploadCanceledChangeAvatar(evt) {\r\n" +
                     "        alert(\"Người dùng hủy bỏ tải lên máy chủ hoặc mất kết nối với máy chủ.\");\r\n" +
                     "   }\r\n" +
                     "  </script>\r\n" +
                     "  <input type=hidden id=\"txtChangeAvatarUpdateId\" value=\"\">\r\n" +
                       "  <div class=DatabaseFunction>\r\n" +
                       "        <ul>\r\n" +
                       "            <li onclick=\"javascript:uploadFileChangeAvatar();\"><img class=image src=\""+ButtonUrl+"/Save.png\"><div>Ghi lại</div></li>\r\n" +
                       "            <li onclick=\"javascript:ClientBack();\"><img class=image src=\"" + ButtonUrl + "/back.png\"><div>Quay lại</div></li>\r\n" +
                       "        </ul>\r\n" +
                       "  </div>\r\n" +
                       "<div class=CssFormSaveUpdate>\r\n" +
                     "  <h3>Thay đổi ảnh đại diện</h3>\r\n" +
                     " <div id=divCallSaveAvatarProcessing class=CssProcessing></div>\r\n" +
                     "  <table>\r\n" +
                   "    <tr>\r\n" +
                   "         <td class=col1>Ảnh đại diện</td>\r\n" +
                   "         <td><input type=hidden id=\"txtUploadFileChangeAvatar\"><input type=\"file\" name=\"fileToUploadChangeAvatar[]\" id=\"fileToUploadChangeAvatar\" onchange=\"fileSelectedChangeAvatar();\" /></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "           <td></td>\r\n" +
                   "           <td>\r\n" +
                   "               <div id=\"progressNumberChangeAvatar\"></div>\r\n" +
                   "               <div id=\"fileNameChangeAvatar\">\r\n" +
                   "               </div>\r\n" +
                   "               <div id=\"fileSizeChangeAvatar\">\r\n" +
                   "               </div>\r\n" +
                   "               <div id=\"fileTypeChangeAvatar\">\r\n" +
                   "               </div>\r\n" +
                   "           </td>\r\n" +
                   "   </tr>\r\n" +
                    //"   <tr>\r\n" +
                    //"            <td class=c1></td>\r\n" +
                    //"            <td class=c2><input type=button class=button value=\"Chấp nhận\" onclick=\"javascript:uploadFileChangeAvatar();\"><input type=button class=button value=\"Quay lại\" onclick=\"javascript:ClientBack();\"></td>\r\n" +
                    //"   </tr>\r\n" +
                   "  </table>\r\n" +
                   "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }



        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawChangeAttachDocForm(string SiteId, string GroupDataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                string DocCaption = "Tài liệu gắn kèm:";
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonUrl = WebConfig.GetButtonIconRoot(OSiteParam);

                string Html =
                     "<script language=javascript>\r\n " +
                     "function fileSelectedChangeAttachDoc() {\r\n" +
                     "    var file = document.getElementById('fileToUploadChangeAttachDoc').files[0];\r\n" +
                     "    if (file) {\r\n" +
                     "        var fileSize = 0;\r\n" +
                     "        if (file.size > 1024 * 1024)\r\n" +
                     "            fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';\r\n" +
                     "        else\r\n" +
                     "            fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';\r\n" +
                     "        document.getElementById('fileNameChangeAttachDoc').innerHTML = 'Tên tệp: ' + file.name;\r\n" +
                     "        document.getElementById('fileSizeChangeAttachDoc').innerHTML = 'Kích cỡ: ' + fileSize;\r\n" +
                     "        document.getElementById('fileTypeChangeAttachDoc').innerHTML = 'Loại tệp: ' + file.type;\r\n" +
                     "    }\r\n" +
                     "}\r\n" +

                     "function uploadFileChangeAttachDoc() {\r\n" +
                     "    if(document.getElementById('fileToUploadChangeAttachDoc').value==''){\r\n" +
                     "       document.getElementById('txtUploadFileChangeAttachDoc').value='';\r\n" +
                     "       CallSave();\r\n" +
                     "       return;\r\n" +
                     "   }\r\n" +
                     "    DataId = document.getElementById('txtChangeAttachDocUpdateId').value;\r\n" +
                     "    var fd = new FormData();\r\n" +
                     "    fd.append(\"fileToUpload\", document.getElementById('fileToUploadChangeAttachDoc').files[0]);\r\n" +
                     "    var xhr = new XMLHttpRequest();\r\n" +
                     "    xhr.upload.addEventListener(\"progress\", uploadProgressChangeAttachDoc, false);\r\n" +
                     "    xhr.addEventListener(\"load\", uploadCompleteChangeAttachDoc, false);\r\n" +
                     "    xhr.addEventListener(\"error\", uploadFailedChangeAttachDoc, false);\r\n" +
                     "    xhr.addEventListener(\"abort\", uploadCanceledChangeAttachDoc, false);\r\n" +
                     "    xhr.open(\"POST\", \"CmsUploadAttachFileHandler.ashx?DataId=\"+DataId+\"&sid=" + SiteId + "&uni=" + WebSessionUtility.GetCurrentLoginUser().AssetCode + "&gid=" + GroupDataId + "\");\r\n" +
                     "    xhr.send(fd);\r\n" +
                     "}\r\n" +

                     "function uploadProgressChangeAttachDoc(evt) {\r\n" +
                     "    if (evt.lengthComputable) {\r\n" +
                     "    }\r\n" +
                     "    else {\r\n" +
                     "        document.getElementById('progressNumberChangeAttachDoc').innerHTML = 'Không tính toán được thời gian';\r\n" +
                     "    }\r\n" +
                     "}\r\n" +

                     " function CallSave()\r\n" +
                     " {\r\n" +
                     "      document.getElementById('divCallSaveProcessing').innerHTML='Tiến hành cập nhật và đánh index tìm kiếm...';\r\n" +
                     "      setTimeout('RealCallSave()',10);\r\n" +
                     " }\r\n" +

                     " function RealCallSave()\r\n" +
                     " {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      DataId = document.getElementById('txtChangeAttachDocUpdateId').value;\r\n" +
                     "      uploadFile = document.getElementById('txtUploadFileChangeAttachDoc').value;\r\n" +
                     "      ParentDataId=document.getElementById('txtParentDataId').value;\r\n" +
                     "      AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideSaveAttachDoc(SiteId,'" + GroupDataId + "',ParentDataId, DataId, uploadFile).value;\r\n" +
                     "      document.getElementById('divCallSaveProcessing').innerHTML='';\r\n" +
                     "      if(AjaxOut.Error)\r\n" +
                     "      {\r\n" +
                     "          alert(AjaxOut.InfoMessage);\r\n" +
                     "          return;\r\n" +
                     "      }\r\n" +
                     "      if(AjaxOut.RetUrl!='')\r\n" +
                     "      {\r\n" +
                     "          window.open(AjaxOut.RetUrl,'_self');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          ClientBack();\r\n" +
                     "      }\r\n" +
                     " }\r\n" +


                     "function uploadCompleteChangeAttachDoc(evt) {\r\n" +
                     "    /* This event is raised when the server send back a response */\r\n" +
                     "    document.getElementById('txtUploadFileChangeAttachDoc').value=evt.target.responseText;\r\n" +
                     "    //doan nay chay upload vao day...\r\n" +
                     "    CallSave();\r\n" +
                     "   }\r\n  " +

                       "function uploadFailedChangeAttachDoc(evt) {\r\n" +
                     "       alert(\"Lỗi khi tải tệp dữ liệu lên máy chủ.\");\r\n" +
                     "   }\r\n" +

                     "   function uploadCanceledChangeAttachDoc(evt) {\r\n" +
                     "        alert(\"Người dùng hủy bỏ tải lên máy chủ hoặc mất kết nối với máy chủ.\");\r\n" +
                     "   }\r\n" +
                     "  </script>\r\n" +
                     "  <input type=hidden id=\"txtChangeAttachDocUpdateId\" value=\"\">\r\n" +
                       "  <div class=DatabaseFunction>\r\n" +
                       "        <ul>\r\n" +
                       "            <li onclick=\"javascript:uploadFileChangeAttachDoc();\"><img class=image src=\""+ButtonUrl+"/Save.png\"><div>Ghi lại</div></li>\r\n" +
                       "            <li onclick=\"javascript:ClientBack();\"><img class=image src=\""+ButtonUrl+"/back.png\"><div>Quay lại</div></li>\r\n" +
                       "        </ul>\r\n" +
                       "  </div>\r\n" +

                       "<div class=CssFormSaveUpdate>\r\n" +
                     "  <h3>Thay đổi -  " + DocCaption + "</h3>\r\n" +
                     "<div id=divCallSaveProcessing class=\"CssProcessing\"></div>\r\n" +
                     "  <table>\r\n" +
                   "    <tr>\r\n" +
                   "         <td class=col1>" + DocCaption + "</td>\r\n" +
                   "         <td><input type=hidden id=\"txtUploadFileChangeAttachDoc\"><input type=\"file\" name=\"fileToUploadChangeAttachDoc[]\" id=\"fileToUploadChangeAttachDoc\" onchange=\"fileSelectedChangeAttachDoc();\" /></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "           <td></td>\r\n" +
                   "           <td>\r\n" +
                   "               <div id=\"progressNumberChangeAttachDoc\"></div>\r\n" +
                   "               <div id=\"fileNameChangeAttachDoc\">\r\n" +
                   "               </div>\r\n" +
                   "               <div id=\"fileSizeChangeAttachDoc\">\r\n" +
                   "               </div>\r\n" +
                   "               <div id=\"fileTypeChangeAttachDoc\">\r\n" +
                   "               </div>\r\n" +
                   "           </td>\r\n" +
                   "   </tr>\r\n" +
                    //"   <tr>\r\n" +
                    //"            <td class=c1></td>\r\n" +
                    //"            <td class=c2><input type=button class=button value=\"Chấp nhận\" onclick=\"javascript:uploadFileChangeAttachDoc();\"><input type=button class=button value=\"Quay lại\" onclick=\"javascript:ClientBack();\"></td>\r\n" +
                    //"   </tr>\r\n" +
                   "  </table>\r\n" +
                   "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }



        //[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        //public static AjaxOut DrawUpdateForm(string SiteId, string GroupDataId)
        //{
        //    AjaxOut OAjaxOut = new AjaxOut();
        //    try
        //    {
        //        WebSessionUtility.CheckSessionTimeOut();
        //        GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(SiteId, GroupDataId);
        //        SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
        //        string ButtonUrl = WebConfig.GetButtonIconRoot(OSiteParam);

        //        string StyleDisp = " style=\"display:none;\"";
        //        if (OGroupData.ShowBody)
        //        {
        //            StyleDisp = "";
        //        }
               
        //        string Html =
        //             "  <script language=javascript>\r\n" +
        //             "        function SaveUpdate()\r\n" +
        //             "        {\r\n" +
        //             "              document.getElementById('divUpdateProcessing').innerHTML='Tiến hành cập nhật và đánh index tìm kiếm...';\r\n" +
        //             "              setTimeout('RealSaveUpdate()',10);\r\n"+
        //             "        }\r\n"+

        //             "        function RealSaveUpdate()\r\n" +
        //             "        {\r\n" +
        //             "          DataId = document.getElementById('txtUpdateId').value;\r\n" +
        //             "          Alias = document.getElementById('txtUpdateAlias').value;\r\n" +
        //             "          Subject = document.getElementById('txtUpdateSubject').value;\r\n" +
        //             "          Description = document.getElementById('txtUpdateDescription').value;\r\n" +
        //             "          Body='';\r\n" +
        //             "          if(FCKeditorAPI!=null){\r\n" +
        //             "              oEditor = FCKeditorAPI.GetInstance('FCKeditorBodyUpdate');\r\n" +
        //             "              Body= oEditor.GetXHTML( true ); \r\n" +
        //             "          }\r\n" +
        //             "          Source = document.getElementById('txtUpdateSource').value;\r\n" +
        //             "          Url = document.getElementById('txtUpdateUrl').value;\r\n" +
        //             "          Target = document.getElementById('txtUpdateTarget').value;\r\n" +
        //             "          SortIndex = document.getElementById('txtUpdateSortIndex').value;\r\n" +
        //             "          ParentDataId=document.getElementById('txtParentDataId').value;\r\n" +




        //             "      DocType='';\r\n" +
        //             "      if(document.getElementById('drpUpdateSelectDocType')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocType=document.getElementById('drpUpdateSelectDocType').value;\r\n" +
        //             "      }\r\n" +

        //             "      DocField='';\r\n" +
        //             "      if(document.getElementById('drpUpdateSelectDocField')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocField=document.getElementById('drpUpdateSelectDocField').value;\r\n" +
        //             "      }\r\n" +

        //             "      DocReleaseFrom='';\r\n" +
        //             "      if(document.getElementById('drpUpdateSelectDocReleaseFrom')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocReleaseFrom=document.getElementById('drpUpdateSelectDocReleaseFrom').value;\r\n" +
        //             "      }\r\n" +
                     
        //             "      DocSigner='';\r\n" +
        //             "      if(document.getElementById('drpUpdateSelectDocSigner')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocSigner=document.getElementById('drpUpdateSelectDocSigner').value;\r\n" +
        //             "      }\r\n" +


        //             "      DocStatus='';\r\n" +
        //             "      if(document.getElementById('drpUpdateSelectDocStatus')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          DocStatus=document.getElementById('drpUpdateSelectDocStatus').value;\r\n" +
        //             "      }\r\n" +

        //             "      ReleaseDate='';\r\n" +
        //             "      if(document.getElementById('txtUpdateReleaseDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          ReleaseDate=document.getElementById('txtUpdateReleaseDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      EffectedDate='';\r\n" +
        //             "      if(document.getElementById('txtUpdateEffectedDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          EffectedDate=document.getElementById('txtUpdateEffectedDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      EndEffectedDate='';\r\n" +
        //             "      if(document.getElementById('txtEndUpdateEffectedDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          EndEffectedDate=document.getElementById('txtEndUpdateEffectedDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      SignDate='';\r\n" +
        //             "      if(document.getElementById('txtUpdateSignDate')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          SignDate=document.getElementById('txtUpdateSignDate').value;\r\n" +
        //             "      }\r\n" +

        //             "      ReplaceDoc='';\r\n" +
        //             //"      if(document.getElementById('txtUpdateReplaceDoc')!=null)\r\n" +
        //             //"      {\r\n" +
        //             //"          ReplaceDoc=document.getElementById('txtUpdateReplaceDoc').value;\r\n" +
        //             //"      }\r\n" +

        //             "      ModifyDoc='';\r\n" +
        //             //"      if(document.getElementById('txtUpdateModifyDoc')!=null)\r\n" +
        //             //"      {\r\n" +
        //             //"          ModifyDoc=document.getElementById('txtUpdateModifyDoc').value;\r\n" +
        //             //"      }\r\n" +


        //             "      VoteType='';\r\n" +
        //             "      if(document.getElementById('drpUpdateSelectVoteType')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          VoteType=document.getElementById('drpUpdateSelectVoteType').value;\r\n" +
        //             "      }\r\n" +

        //             "      IsNew=document.getElementById('drpSelectIsNew').value;\r\n"+
                     
        //             "      AttachedSearchable='0';\r\n" +
        //             "      if(document.getElementById('drpUpdateSelectSearchable')!=null)\r\n" +
        //             "      {\r\n" +
        //             "          AttachedSearchable=document.getElementById('drpUpdateSelectSearchable').value;\r\n" +
        //             "      }\r\n" +
        //             "      document.getElementById('divUpdateProcessing').innerHTML='';\r\n" +
        //             "      AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideSave(SiteId,'" + GroupDataId + "',ParentDataId,DataId, Alias, Subject, Description, Body, Source, Url, Target, SortIndex,DocType,DocField, DocReleaseFrom,DocSigner, DocStatus,SignDate, ReleaseDate,EffectedDate,EndEffectedDate,ReplaceDoc,ModifyDoc, VoteType, IsNew, AttachedSearchable).value;\r\n" +
        //             "      if(AjaxOut.Error)\r\n" +
        //             "      {\r\n" +
        //             "          alert(AjaxOut.InfoMessage);\r\n" +
        //             "          return;\r\n" +
        //             "      }\r\n" +
                     
        //             "      if(AjaxOut.RetUrl!='')\r\n"+
        //             "      {\r\n"+
        //             "          window.open(AjaxOut.RetUrl,'_self');\r\n" +
        //             "      }\r\n"+
        //             "      else\r\n"+
        //             "      {\r\n"+
        //             "          document.getElementById('divListForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
        //             "          ClientBack();\r\n" +
        //             "      }\r\n"+
        //             "  }\r\n"+
        //             "  </script>\r\n" +
        //           "  <input type=hidden id=txtUpdateId>\r\n" +
        //           "  <h3>Sửa dữ liệu</h3>\r\n" +
        //            "  <div class=DatabaseFunction>\r\n" +
        //            "        <ul>\r\n" +
        //            "            <li onclick=\"javascript:SaveUpdate();\"><img class=image src=\""+ButtonUrl+"/Save.png\"><div>Ghi lại</div></li>\r\n" +
        //            "            <li onclick=\"javascript:ClientBack();\"><img class=image src=\""+ButtonUrl+"/back.png\"><div>Quay lại</div></li>\r\n" +
        //            "        </ul>\r\n" +
        //            "  </div>\r\n" +
        //            "<div class=CssFormSaveUpdate>\r\n"+ 
        //            "<div id=divUpdateProcessing class=\"CssProcessing\"></div>\r\n"+
        //           "  <table>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Mã:</td>\r\n" +
        //           "        <td class=c2><input id=txtUpdateAlias class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Tiêu đề:</td>\r\n" +
        //           "        <td class=c2><input id=txtUpdateSubject class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1 style=\"vertical-align:top;\">Mô tả:</td>\r\n" +
        //           "        <td class=c2><textarea id=txtUpdateDescription class=textarea type=textbox></textarea></td>\r\n" +
        //           "    </tr>\r\n" +
        //             "   <tr " + StyleDisp + ">\r\n" +
        //             "        <td class=c1 style=\"vertical-align:top;\">Nội dung:</td>\r\n" +
        //             "        <td class=c2>\r\n" +
        //             "                <textarea type=hidden id=\"FCKeditorBodyUpdate\" name=\"FCKeditorBodyUpdate\"></textarea>\r\n" +
        //             "               <script type=\"text/javascript\" src=\"/fckeditor/fckeditor.js\"></script>\r\n" +
        //             "               <script type=\"text/javascript\">\r\n" +
        //             "                   var oFCKeditorUpdate = new FCKeditor('FCKeditorBodyUpdate');\r\n" +
        //             "                   oFCKeditorUpdate.BasePath = \"/fckeditor/\";\r\n" +
        //             "                   oFCKeditorUpdate.Height = \"600\";\r\n" +
        //             "                   oFCKeditorUpdate.ReplaceTextarea();\r\n" +
        //             "               </script>\r\n" +
        //             "        </td>\r\n" +
        //             "    </tr>\r\n";


        //        string SelectVoteType = "";
        //        if (OGroupData.frkDataTypeId.Equals("vote"))
        //        {
        //            SelectVoteType = " <select id=drpUpdateSelectVoteType>\r\n" +
        //                             "      <option value=\"one\">Chỉ chọn 1 phương án</option>\r\n" +
        //                             "      <option value=\"two\">Chọn nhiều phương án</option>\r\n" +
        //                             "      <option value=\"text\">Nhập text</option>\r\n" +
        //                             " </select>\r\n";
        //        }

        //        string SelectIsNew = " <select id=\"drpSelectIsNew\">\r\n" +
        //                             "      <option value=\"0\">Tài liệu bình thường</option>\r\n" +
        //                             "      <option value=\"1\">Tài liệu mới</option>\r\n" +
        //                             " </select>\r\n";


        //        if (OGroupData.frkDataTypeId.Equals("document"))
        //        {
        //            string SelectSearchable =
        //            " <select id=\"drpUpdateSelectSearchable\">\r\n" +
        //            "      <option value=\"0\">Không tìm kiếm toàn văn được</option>\r\n" +
        //            "      <option value=\"1\" selected>Tìm kiếm toàn văn được</option>\r\n" +
        //            " </select>\r\n";

        //            string SelectDocumentType =
        //                "<select id=drpUpdateSelectDocType class=drplist>\r\n";
        //            DocTypeCls[] DocTypes = DocTypeProcessBll.ReadingDocType(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocTypes.Length; iIndex++)
        //            {
        //                SelectDocumentType += "   <option value=\"" + DocTypes[iIndex].DocTypeId + "\">" + DocTypes[iIndex].DocTypeName + "</option>\r\n";
        //            }
        //            SelectDocumentType += "</select>\r\n";


        //            string SelectDocField =
        //               "<select id=drpUpdateSelectDocField class=drplist>\r\n";
        //            DocFieldCls[] DocFields = DocFieldProcessBll.ReadingDocField(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocFields.Length; iIndex++)
        //            {
        //                SelectDocField += "   <option value=\"" + DocFields[iIndex].DocFieldId + "\">" + DocFields[iIndex].DocFieldName + "</option>\r\n";
        //            }
        //            SelectDocField += "</select>\r\n";

        //            string SelectDocReleaseFrom =
        //                "<select id=drpUpdateSelectDocReleaseFrom class=drplist>\r\n";
        //            DocReleaseFromCls[] DocReleaseFroms = DocReleaseFromProcessBll.ReadingDocReleaseFrom(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocReleaseFroms.Length; iIndex++)
        //            {
        //                SelectDocReleaseFrom += "   <option value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + DocReleaseFroms[iIndex].DocReleaseFromName + "</option>\r\n";
        //            }
        //            SelectDocReleaseFrom += "</select>\r\n";

        //            string SelectDocSigner =
        //              "<select id=drpUpdateSelectDocSigner class=drplist>\r\n";
        //            DocSignerCls[] DocSigners = DocSignerProcessBll.ReadingDocSigner(SiteId, GroupDataId);
        //            for (int iIndex = 0; iIndex < DocSigners.Length; iIndex++)
        //            {
        //                SelectDocSigner += "   <option value=\"" + DocSigners[iIndex].DocSignerId + "\">" + DocSigners[iIndex].DocSignerName + "</option>\r\n";
        //            }
        //            SelectDocSigner += "</select>\r\n";


                    
        //            string SelectStatus =
        //                "<select id=drpUpdateSelectDocStatus class=drplist>\r\n" +
        //                "   <option value=\"0\">Hết hiệu lực</option>\r\n" +
        //                "   <option value=\"1\">Có hiệu lực</option>\r\n" +
        //                "</select>\r\n";
        //            Html +=
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Loại văn bản:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocumentType + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Lĩnh vực:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocField + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Cơ quan ban hành:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocReleaseFrom + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Người ký:</td>\r\n" +
        //             "        <td class=c2>" + SelectDocSigner + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Trạng thái:</td>\r\n" +
        //             "        <td class=c2>" + SelectStatus + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày ký:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtUpdateSignDate") + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày ban hành:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtUpdateReleaseDate") + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày hiệu lực:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtUpdateEffectedDate") + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Ngày hết hiệu lực:</td>\r\n" +
        //             "        <td class=c2>" + LookUpUtilities.GenerateLookUpDate("txtEndUpdateEffectedDate") + "</td>\r\n" +
        //             "    </tr>\r\n" +
        //             "    <tr>\r\n" +
        //             "        <td class=c1>Tìm toàn văn:</td>\r\n" +
        //             "        <td class=c2>" + SelectSearchable + "</td>\r\n" +
        //             "    </tr>\r\n";
        //        }

        //        Html +=

        //           "    <tr>\r\n" +
        //           "        <td class=c1>Nguồn:</td>\r\n" +
        //           "        <td class=c2><input id=txtUpdateSource class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Url:</td>\r\n" +
        //           "        <td class=c2><input id=txtUpdateUrl class=textbox type=textbox></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Kiểu mở:</td>\r\n" +
        //           "        <td class=c2><input id=txtUpdateTarget class=textbox type=textbox value=\"_self\"></td>\r\n" +
        //           "    </tr>\r\n" +
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Thứ tự:</td>\r\n" +
        //           "        <td class=c2><input id=txtUpdateSortIndex class=textbox type=textbox value=\"0\"></td>\r\n" +
        //           "    </tr>\r\n";
        //        if (OGroupData.frkDataTypeId.Equals("vote"))
        //        {
        //            Html +=
        //                "    <tr>\r\n" +
        //                "        <td class=c1>Loại đánh giá:</td>\r\n" +
        //                "        <td class=c2>" + SelectVoteType + "</td>\r\n" +
        //                "    </tr>\r\n";
        //        }
        //        Html +=
        //           "    <tr>\r\n" +
        //           "        <td class=c1>Trạng thái:</td>\r\n" +
        //           "        <td class=c2>" + SelectIsNew + "</td>\r\n" +
        //           "    </tr>\r\n" +
        //            //"    <tr>\r\n" +
        //            //"        <td class=c1></td>\r\n" +
        //            //"        <td class=c2><input type=button class=button value=\"Chấp nhận\" onclick=\"javascript:SaveUpdate();\"><input type=button class=button value=\"Quay lại\" onclick=\"javascript:ClientBack();\"></td>\r\n" +
        //            //"    </tr>\r\n" +
        //           "  </table>\r\n" +
        //           "</div>\r\n";
                   

        //        OAjaxOut.HtmlContent = Html;
        //    }
        //    catch (Exception ex)
        //    {
        //        OAjaxOut.InfoMessage = ex.Message.ToString();
        //        OAjaxOut.HtmlContent = ex.Message.ToString();
        //        OAjaxOut.Error = true;
        //    }

        //    return OAjaxOut;
        //}


        
        

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDelete(string SiteId, string GroupDataId,string ParentDataId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                GroupDataCls OGroupDataCls = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).DeleteCmsData(SiteId, DataId);
                if (OGroupDataCls.frkDataTypeId.Equals("document"))
                {
                    OAjaxOut.RetUrl = "DocumentInputData.aspx?gid="+GroupDataId;
                }
                else
                {
                    OAjaxOut.HtmlContent = ServerSideReading(SiteId, GroupDataId, ParentDataId).HtmlContent;
                }
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideCreateDataModel(string SiteId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, DataId);
                OAjaxOut.RetObject = OCmsData;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideSaveAvatar(string SiteId, string GroupDataId, string ParentDataId, string DataId, string uploadFile)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ChangeAvatarFile(SiteId, DataId,uploadFile);
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                if (OGroupData.frkDataTypeId.Equals("document"))
                {
                    OAjaxOut.RetUrl = "DocumentInputData.aspx?gid=" + GroupDataId;
                }
                else
                {
                    OAjaxOut.HtmlContent = ServerSideReading(SiteId, GroupDataId, ParentDataId).HtmlContent;
                }
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }


        
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideSaveAttachDoc(string SiteId, string GroupDataId, string ParentDataId, string DataId, string uploadFile)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ChangeAttachDocFile(SiteId, DataId, uploadFile);
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                if (OGroupData.frkDataTypeId.Equals("document"))
                {
                    OAjaxOut.RetUrl = "DocumentInputData.aspx?gid=" + GroupDataId;
                }
                else
                {
                    OAjaxOut.HtmlContent = ServerSideReading(SiteId, GroupDataId, ParentDataId).HtmlContent;
                }
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }



        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSidePublic(string SiteId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).PublicData(null, SiteId, DataId);
                
                OAjaxOut.HtmlContent =
                    "<input type=button class=button  value=\"Ngưng phát hành\" onclick=\"javascript:ClientUnPublic('" + DataId + "');\">";
                OAjaxOut.InfoMessage = "Đã phát hành";
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideUnPublic(string SiteId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).UnPublicData(null, SiteId, DataId);
                
                OAjaxOut.HtmlContent =
                    "<input type=button class=button value=\"Phát hành\" onclick=\"javascript:ClientPublic('" + DataId + "');\">";
                OAjaxOut.InfoMessage = "Chưa phát hành";
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }

        ////////////////////////////// DOCUMENT //////////////



        public static AjaxOut RenderSearchDocument(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string gid = (string)WebEnvironments.Request(SiteId, "gid");
                if (string.IsNullOrEmpty(gid)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, gid);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);

                string documentno = (string)WebEnvironments.Request(SiteId, "documentno");
                if (documentno == null) documentno = "";

                string Subject = (string)WebEnvironments.Request(SiteId, "Subject");
                if (Subject == null) Subject = "";

                string sfd = (string)WebEnvironments.Request(SiteId, "sfd");
                if (sfd == null) sfd = "";

                string std = (string)WebEnvironments.Request(SiteId, "std");
                if (std == null) std = "";

                string rfd = (string)WebEnvironments.Request(SiteId, "rfd");
                if (rfd == null) rfd = "";

                string rtd = (string)WebEnvironments.Request(SiteId, "rtd");
                if (rtd == null) rtd = "";

                string efd = (string)WebEnvironments.Request(SiteId, "efd");
                if (efd == null) efd = "";

                string etd = (string)WebEnvironments.Request(SiteId, "etd");
                if (etd == null) etd = "";


                string eefd = (string)WebEnvironments.Request(SiteId, "eefd");
                if (eefd == null) eefd = "";

                string eetd = (string)WebEnvironments.Request(SiteId, "eetd");
                if (eetd == null) eetd = "";

                string ip = (string)WebEnvironments.Request(SiteId, "ip");
                if (ip == null) ip = "";

                string sab = (string)WebEnvironments.Request(SiteId, "sab");
                if (sab == null) sab = "";


                string releasefrom = (string)WebEnvironments.Request(SiteId, "releasefrom");
                if (releasefrom == null) releasefrom = "";

                string docfield = (string)WebEnvironments.Request(SiteId, "docfield");
                if (docfield == null) docfield = "";

                string doctype = (string)WebEnvironments.Request(SiteId, "doctype");
                if (doctype == null) doctype = "";

                string docsigner = (string)WebEnvironments.Request(SiteId, "signer");
                if (docsigner == null) docsigner = "";

                string fulltextsearch = (string)WebEnvironments.Request(SiteId, "fulltextsearch");
                if (string.IsNullOrEmpty(fulltextsearch)) fulltextsearch = "0";

                string fullTextSearchKeyword = (string)WebEnvironments.Request(SiteId, "fullTextSearchKeyword");
                if (string.IsNullOrEmpty(fullTextSearchKeyword)) fullTextSearchKeyword = "";

                DocReleaseFromCls[] DocReleaseFroms = DocReleaseFromProcessBll.ReadingDocReleaseFrom(SiteId, OGroupData.GroupDataId);
                string SelectReleaseFrom =
                    " <select class=\"drpselect\" id=\"drpDocumentReleasefrom\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocReleaseFroms.Length; iIndex++)
                {
                    if (releasefrom.Equals(DocReleaseFroms[iIndex].DocReleaseFromId))
                    {
                        SelectReleaseFrom += "    <option selected value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + DocReleaseFroms[iIndex].DocReleaseFromName + "</option>\r\n";
                    }
                    else
                    {
                        SelectReleaseFrom += "    <option value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + DocReleaseFroms[iIndex].DocReleaseFromName + "</option>\r\n";
                    }
                }
                SelectReleaseFrom +=
                    " </select>\r\n";

                DocSignerCls[] DocSigners = DocSignerProcessBll.ReadingDocSigner(SiteId, OGroupData.GroupDataId);
                string SelectSigner =
                    " <select class=\"drpselect\" id=\"drpDocumentSigner\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocSigners.Length; iIndex++)
                {
                    if (docsigner.Equals(DocSigners[iIndex].DocSignerId))
                    {
                        SelectSigner += "    <option selected value=\"" + DocSigners[iIndex].DocSignerId + "\">" + DocSigners[iIndex].DocSignerName + "</option>\r\n";
                    }
                    else
                    {
                        SelectSigner += "    <option value=\"" + DocSigners[iIndex].DocSignerId + "\">" + DocSigners[iIndex].DocSignerName + "</option>\r\n";
                    }
                }
                SelectSigner +=
                    " </select>\r\n";

                string SelectFullText =
                     " <select id=drpSelectFullText class=\"drpselect\" >\r\n" +
                     "  <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                     "  <option value=\"1\">Tìm toàn văn</option>\r\n" +
                     " </select>\r\n";

                if (fulltextsearch.Equals("1"))
                {
                    SelectFullText =
                     " <select id=drpSelectFullText class=\"drpselect\" >\r\n" +
                     "  <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                     "  <option selected value=\"1\">Tìm toàn văn</option>\r\n" +
                     " </select>\r\n";
                }

                DocTypeCls[] DocTypes = DocTypeProcessBll.ReadingDocType(SiteId, OGroupData.GroupDataId);
                string SelectDocType =
                    " <select class=\"drpselect\" id=\"drpDocumentDocType\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocTypes.Length; iIndex++)
                {
                    if (doctype.Equals(DocTypes[iIndex].DocTypeId))
                    {
                        SelectDocType += "    <option selected value=\"" + DocTypes[iIndex].DocTypeId + "\">" + DocTypes[iIndex].DocTypeName + "</option>\r\n";
                    }
                    else
                    {
                        SelectDocType += "    <option value=\"" + DocTypes[iIndex].DocTypeId + "\">" + DocTypes[iIndex].DocTypeName + "</option>\r\n";
                    }
                }
                SelectDocType +=
                    " </select>\r\n";


                DocFieldCls[] DocFields = DocFieldProcessBll.ReadingDocField(SiteId, OGroupData.GroupDataId);
                string SelectDocField =
                    " <select class=\"drpselect\" id=\"drpDocumentDocField\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocFields.Length; iIndex++)
                {
                    if (docfield.Equals(DocFields[iIndex].DocFieldId))
                    {
                        SelectDocField += "    <option selected value=\"" + DocFields[iIndex].DocFieldId + "\">" + DocFields[iIndex].DocFieldName + "</option>\r\n";
                    }
                    else
                    {
                        SelectDocField += "    <option value=\"" + DocFields[iIndex].DocFieldId + "\">" + DocFields[iIndex].DocFieldName + "</option>\r\n";
                    }
                }
                SelectDocField +=
                    " </select>\r\n";

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "divSearchForm");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                string SelectPublishing =
                    "<select class=\"drpselect\" id=drpSelectPublishing>\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n" +
                    "   <option value=\"0\">Chưa phát hành</option>\r\n" +
                    "   <option value=\"1\">Đã phát hành</option>\r\n" +
                    "</select>\r\n";

                if (ip.Equals("0"))
                {
                    SelectPublishing =
                    "<select class=\"drpselect\" id=drpSelectPublishing>\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n" +
                    "   <option selected value=\"0\">Chưa phát hành</option>\r\n" +
                    "   <option value=\"1\">Đã phát hành</option>\r\n" +
                    "</select>\r\n";
                }
                if (ip.Equals("1"))
                {
                    SelectPublishing =
                    "<select class=\"drpselect\" id=drpSelectPublishing>\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n" +
                    "   <option value=\"0\">Chưa phát hành</option>\r\n" +
                    "   <option selected value=\"1\">Đã phát hành</option>\r\n" +
                    "</select>\r\n";
                }






                string SelectSearchable =
                   "<select class=\"drpselect\" id=drpSelectSearchableForSearch>\r\n" +
                   "   <option value=\"\">Toàn bộ</option>\r\n" +
                   "   <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                   "   <option value=\"1\">Tìm toàn văn</option>\r\n" +
                   "</select>\r\n";

                if (sab.Equals("0"))
                {
                    SelectSearchable =
                    "<select class=\"drpselect\" id=drpSelectSearchableForSearch>\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n" +
                    "   <option selected value=\"0\">Không tìm toàn văn</option>\r\n" +
                    "   <option value=\"1\">Tìm toàn văn</option>\r\n" +
                    "</select>\r\n";
                }
                if (sab.Equals("1"))
                {
                    SelectSearchable =
                    "<select class=\"drpselect\" id=drpSelectSearchableForSearch>\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n" +
                    "   <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                    "   <option selected value=\"1\">Tìm toàn văn</option>\r\n" +
                    "</select>\r\n";
                }
                string Html =
                    " <script language=javascript>\r\n" +
                     "  function CollapseExpandSearchForm(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +


                    "   function ClientDoSearchDocument(PageIndex)\r\n" +
                    "   {\r\n" +
                    "       DocumentNo=document.getElementById('txtDocumentNo').value;\r\n" +
                    "       Subject=document.getElementById('txtDocumentSubject').value;\r\n" +
                    "       SignFromDate=document.getElementById('txtSignFromDate').value;\r\n" +
                    "       SignToDate =document.getElementById('txtSignToDate').value;\r\n" +
                    "       ReleaseFromDate=document.getElementById('txtReleaseFromDate').value;\r\n" +
                    "       ReleaseToDate =document.getElementById('txtReleaseToDate').value;\r\n" +
                    "       EffectedFromDate=document.getElementById('txtEffectedFromDate').value;\r\n" +
                    "       EffectedToDate=document.getElementById('txtEffectedToDate').value;\r\n" +

                    "       EndEffectedFromDate=document.getElementById('txtEndEffectedFromDate').value;\r\n" +
                    "       EndEffectedToDate=document.getElementById('txtEndEffectedToDate').value;\r\n" +

                    "       DocumentReleasefrom=document.getElementById('drpDocumentReleasefrom').value;\r\n" +
                    "       DocumentDocType=document.getElementById('drpDocumentDocType').value;\r\n" +
                    "       DocumentDocField=document.getElementById('drpDocumentDocField').value;\r\n" +
                    "       DocumentSigner=document.getElementById('drpDocumentSigner').value;\r\n" +
                    "       SortField=document.getElementById('drpSelectSortField').value;\r\n" +
                    "       SortType=document.getElementById('drpSortType').value;\r\n" +
                    "       PageSize = document.getElementById('drpSelectPageSize').value;\r\n" +
                    "       fulltextsearch = document.getElementById('drpSelectFullText').value;\r\n" +
                    "       fullTextSearchKeyword = document.getElementById('txtFullTextSearch').value;\r\n" +
                    "       ip = document.getElementById('drpSelectPublishing').value;\r\n" +
                    "       sab = document.getElementById('drpSelectSearchableForSearch').value;\r\n" +
                    "       ps = document.getElementById('drpSelectStatus').value;\r\n"+
                    "       window.open('" + ORenderInfo.JumpPageAspx + "?gid=" + gid + "&documentno='+DocumentNo+'&subject='+Subject+'&sfd='+SignFromDate+'&std='+SignToDate+'&rfd='+ReleaseFromDate+'&rtd='+ReleaseToDate +'&efd='+EffectedFromDate+'&etd='+EffectedToDate+'&eefd='+EndEffectedFromDate+'&eetd='+EndEffectedToDate+'&releasefrom='+DocumentReleasefrom+'&signer='+DocumentSigner+'&doctype='+DocumentDocType+'&docfield='+DocumentDocField+'&SortField='+SortField+'&SortType='+SortType+'&PageSize='+PageSize+'&PageIndex='+PageIndex+'&fulltextsearch='+fulltextsearch+'&fullTextSearchKeyword='+fullTextSearchKeyword+'&ip='+ip+'&sab='+sab+'&ps='+ps,'_self');\r\n" +
                    "   }\r\n" +
                    " </script> \r\n" +
                    " <h3><a href=\"javascript:CollapseExpandSearchForm('divSearchForm');\">Tìm kiếm nâng cao</a></h3> \r\n" +
                    " <div id=\"divSearchForm\" style=\"display:" + DisplayDiv + ";\">\r\n" +

                    " <div>Trạng thái:</div> \r\n" +
                    " <div>" + SelectPublishing + "</div> \r\n" +

                    " <div>Toàn văn:</div> \r\n" +
                    " <div>" + SelectSearchable + "</div> \r\n" +

                    " <div>Số văn bản *:</div> \r\n" +
                    " <div><input type=textbox class=textbox id=txtDocumentNo value=\"" + documentno + "\" /></div> \r\n" +
                    " <div>Tiêu đề / mô tả:</div> \r\n" +
                    " <div><input type=textbox class=textbox id=\"txtDocumentSubject\" value=\"" + Subject + "\" /></div> \r\n" +
                    //" <div>Ngày ký:</div> \r\n" +
                    //" <div>" + LookUpUtilities.GenerateLookUpDate("txtSignFromDate", sfd) + "~" + LookUpUtilities.GenerateLookUpDate("txtSignToDate", std) + "</div> \r\n" +
                    " <div>Ngày ban hành:</div> \r\n" +
                    " <div>" + LookUpUtilities.GenerateLookUpDate("txtReleaseFromDate", rfd) + "~" + LookUpUtilities.GenerateLookUpDate("txtReleaseToDate", rtd) + "</div> \r\n" +
                    " <div>Ngày hiệu lực:</div> \r\n" +
                    " <div>" + LookUpUtilities.GenerateLookUpDate("txtEffectedFromDate", efd) + "~" + LookUpUtilities.GenerateLookUpDate("txtEffectedToDate", etd) + "</div> \r\n" +
                    " <div>Ngày hết hiệu lực:</div> \r\n" +
                    " <div>" + LookUpUtilities.GenerateLookUpDate("txtEndEffectedFromDate", eefd) + "~" + LookUpUtilities.GenerateLookUpDate("txtEndEffectedToDate", eetd) + "</div> \r\n" +

                    " <div>Loại văn bản:</div> \r\n" +
                    " <div>" + SelectDocType + "</div> \r\n" +

                    " <div>Lĩnh vực:</div> \r\n" +
                    " <div>" + SelectDocField + "</div> \r\n" +

                    " <div>Cơ quan ban hành:</div> \r\n" +
                    " <div>" + SelectReleaseFrom + "</div> \r\n" +
                    " <div>Người ký:</div> \r\n" +
                    " <div>" + SelectSigner + "</div> \r\n" +
                    " <div>Toàn văn:</div> \r\n" +
                    " <div>" + SelectFullText + "</div> \r\n" +
                    " <div>Từ khóa toàn văn:</div> \r\n" +
                    " <div><input type=textbox class=textbox id=\"txtFullTextSearch\" value=\"" + fullTextSearchKeyword + "\" /></div> \r\n" +

                    " <div class=search><input type=button class=button value=\"Tìm kiếm văn bản\" onclick=\"javascript:ClientDoSearchDocument(0);\"></div> \r\n" +
                    " </div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderDocumentTypeFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string gid = (string)WebEnvironments.Request(SiteId, "gid");
                if (string.IsNullOrEmpty(gid)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, gid);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string doctype = (string)WebEnvironments.Request(SiteId, "doctype");
                if (doctype == null) doctype = "";


                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterDocumentType");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "block";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocTypeCls[] DocTypes = DocTypeProcessBll.ReadingDocType(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandDocumentType(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandDocumentType('ulFilterDocumentType');\">Loại văn bản</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterDocumentType style=\"display:" + DisplayDiv + "\">\r\n";
                for (int iIndex = 0; iIndex < DocTypes.Length; iIndex++)
                {
                    if (doctype.Equals(DocTypes[iIndex].DocTypeId))
                    {
                        Html += "   <li class=active><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&doctype=" + DocTypes[iIndex].DocTypeId + "\">" + DocTypes[iIndex].DocTypeName + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&doctype=" + DocTypes[iIndex].DocTypeId + "\">" + DocTypes[iIndex].DocTypeName + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderSignerFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string gid = (string)WebEnvironments.Request(SiteId, "gid");
                if (string.IsNullOrEmpty(gid)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, gid);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string Signer = (string)WebEnvironments.Request(SiteId, "Signer");
                if (Signer == null) Signer = "";

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterSigner");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocSignerCls[] Signers = DocSignerProcessBll.ReadingDocSigner(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandSigner(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandSigner('ulFilterSigner');\">Người ký</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterSigner style=\"display:" + DisplayDiv + "\">\r\n";
                for (int iIndex = 0; iIndex < Signers.Length; iIndex++)
                {
                    if (Signer.Equals(Signers[iIndex].DocSignerId))
                    {
                        Html += "   <li class=active><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&signer=" + Signers[iIndex].DocSignerId + "\">" + Signers[iIndex].DocSignerName + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&signer=" + Signers[iIndex].DocSignerId + "\">" + Signers[iIndex].DocSignerName + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderDocReleaseFromFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string gid = (string)WebEnvironments.Request(SiteId, "gid");
                if (string.IsNullOrEmpty(gid)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, gid);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string ReleaseFrom = (string)WebEnvironments.Request(SiteId, "ReleaseFrom");
                if (ReleaseFrom == null) ReleaseFrom = "";

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterReleaseFrom");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocReleaseFromCls[] ReleaseFroms = DocReleaseFromProcessBll.ReadingDocReleaseFrom(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandReleaseFrom(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandReleaseFrom('ulFilterReleaseFrom');\">Cơ quan ban hành</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterReleaseFrom style=\"display:" + DisplayDiv + "\">\r\n";
                for (int iIndex = 0; iIndex < ReleaseFroms.Length; iIndex++)
                {
                    if (ReleaseFrom.Equals(ReleaseFroms[iIndex].DocReleaseFromId))
                    {
                        Html += "   <li class=active><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&ReleaseFrom=" + ReleaseFroms[iIndex].DocReleaseFromId + "\">" + ReleaseFroms[iIndex].DocReleaseFromName + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&ReleaseFrom=" + ReleaseFroms[iIndex].DocReleaseFromId + "\">" + ReleaseFroms[iIndex].DocReleaseFromName + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderDocFieldFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string gid = (string)WebEnvironments.Request(SiteId, "gid");
                if (string.IsNullOrEmpty(gid)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, gid);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string DocField = (string)WebEnvironments.Request(SiteId, "DocField");
                if (DocField == null) DocField = "";


                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterDocField");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocFieldCls[] DocFields = DocFieldProcessBll.ReadingDocField(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandDocField(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          SiteId='" + SiteId + "';\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandDocField('ulFilterDocField');\">Lĩnh vực</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterDocField style=\"display:" + DisplayDiv + "\">\r\n";
                for (int iIndex = 0; iIndex < DocFields.Length; iIndex++)
                {
                    if (DocField.Equals(DocFields[iIndex].DocFieldId))
                    {
                        Html += "   <li class=active><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&DocField=" + DocFields[iIndex].DocFieldId + "\">" + DocFields[iIndex].DocFieldName + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + ORenderInfo.JumpPageAspx + "?gid="+gid+"&DocField=" + DocFields[iIndex].DocFieldId + "\">" + DocFields[iIndex].DocFieldName + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }




        public static AjaxOut RenderDocYearRangeFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string gid = (string)WebEnvironments.Request(SiteId, "gid");
                if (string.IsNullOrEmpty(gid)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, gid);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string YearRange = (string)WebEnvironments.Request(SiteId, "YearRange");
                if (YearRange == null) YearRange = "";


                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterYearRange");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "block";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocYearRangeCls[] YearRanges = DocYearRangeProcessBll.ReadingDocYearRange(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandYearRange(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          Portal.Cms.Render.CmsDataRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandYearRange('ulFilterYearRange');\">Năm ban hành</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterYearRange style=\"display:" + DisplayDiv + "\">\r\n";
                for (int iIndex = 0; iIndex < YearRanges.Length; iIndex++)
                {
                    if (YearRange.Equals(YearRanges[iIndex].DocYearRangeId))
                    {
                        Html += "   <li class=active><a href=\"" + ORenderInfo.JumpPageAspx + "?gid=" + gid + "&YearRange=" + YearRanges[iIndex].DocYearRangeId + "\">" + YearRanges[iIndex].DocYearRangeName + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + ORenderInfo.JumpPageAspx + "?gid=" + gid + "&YearRange=" + YearRanges[iIndex].DocYearRangeId + "\">" + YearRanges[iIndex].DocYearRangeName + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        class SortFieldCls
        {
            public string Field;
            public string Name;

            public SortFieldCls(string _Field, string _Name)
            {
                Field = _Field;
                Name = _Name;
            }
        }

        class SortSizeCls
        {
            public string Field;
            public string Name;

            public SortSizeCls(string _Field, string _Name)
            {
                Field = _Field;
                Name = _Name;
            }
        }


        static string ProcessHighLight(string Subject, string Data)
        {
            if (string.IsNullOrEmpty(Subject))
            {
                return Data;
            }
            else
            {
                Data = Data.Replace(Subject, "<span style=\"background-color:yellow;color:maroon;padding:2px;\">" + Subject + "</span>");
                return Data;
            }
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut RenderSearchDocumentResult(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string gid = (string)WebEnvironments.Request(SiteId, "gid");
                if (string.IsNullOrEmpty(gid)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, gid);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonUrl = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupDataPermission.StaticId, GroupDataPermission.funcAccess, gid, WebSessionUtility.GetCurrentLoginUser().UserId, true);
                bool AllowManage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupDataPermission.StaticId, GroupDataPermission.funcManage, gid, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                bool AllowPublish = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupDataPermission.StaticId, GroupDataPermission.funcPublish, gid, WebSessionUtility.GetCurrentLoginUser().UserId, false);

                SearchParamCls OSearchParam = new SearchParamCls();
                OSearchParam.DataRoot = WebConfig.DataPathRoot(OSiteParam);

                OSearchParam.ActiveGroupData = true;
                OSearchParam.GroupDataId = OGroupData.GroupDataId;
                OSearchParam.SearchDocumentNo = (string)WebEnvironments.Request(SiteId, "documentno");
                if (OSearchParam.SearchDocumentNo == null) OSearchParam.SearchDocumentNo = "";
                OSearchParam.SearchDocumentNo = OSearchParam.SearchDocumentNo.Trim();
                OSearchParam.ActiveSearchDocumentNo = !string.IsNullOrEmpty(OSearchParam.SearchDocumentNo);
                //OSearchParam.IndexesToSearch = @"E:\Projects\QNet.Portal\UniversityNet\UserDataStorage\DocumentArchives\pvfc\Xml\Index";
                //OSearchParam.IndexesToSearchAttachDoc = @"E:\Projects\QNet.Portal\UniversityNet\UserDataStorage\DocumentArchives\pvfc\ArchiveDoc\Index";

                string AssetCode = WebConfig.GetConfigFromXml(OSiteParam, "DefaultAssetCode");
                OSearchParam.IndexesToSearch = WebConfig.DataPathRoot(OSiteParam) + "\\DocumentArchives\\" + AssetCode + "\\Xml\\Index";
                OSearchParam.IndexesToSearchAttachDoc = WebConfig.DataPathRoot(OSiteParam) + "\\DocumentArchives\\" + AssetCode + "\\ArchiveDoc\\Index";


                try
                {
                    int iActiveFullTextSearch = int.Parse((string)WebEnvironments.Request(SiteId, "fulltextsearch"));
                    OSearchParam.ActiveFullTextSearch = iActiveFullTextSearch == 1;
                }
                catch { }

                OSearchParam.fullTextSearchKeyword = (string)WebEnvironments.Request(SiteId, "fullTextSearchKeyword");
                if (string.IsNullOrEmpty(OSearchParam.fullTextSearchKeyword))
                {
                    OSearchParam.ActiveFullTextSearch = false;
                }

                OSearchParam.SearchDocType = (string)WebEnvironments.Request(SiteId, "doctype");
                OSearchParam.ActiveSearchDocType = !string.IsNullOrEmpty(OSearchParam.SearchDocType);
                
                string ip = (string)WebEnvironments.Request(SiteId, "ip");
                if (string.IsNullOrEmpty(ip)) ip = "2";
                OSearchParam.PublishingStatus = int.Parse(ip);

                string sab = (string)WebEnvironments.Request(SiteId, "sab");
                if (string.IsNullOrEmpty(sab)) sab = "2";
                OSearchParam.Searchable = int.Parse(sab);

                OSearchParam.SearchDocField = (string)WebEnvironments.Request(SiteId, "docfield");
                OSearchParam.ActiveSearchDocField = !string.IsNullOrEmpty(OSearchParam.SearchDocField);

                OSearchParam.SearchDocReleaseFrom = (string)WebEnvironments.Request(SiteId, "releasefrom");
                OSearchParam.ActiveSearchDocReleaseFrom = !string.IsNullOrEmpty(OSearchParam.SearchDocReleaseFrom);

                OSearchParam.SearchDocSigner = (string)WebEnvironments.Request(SiteId, "signer");
                OSearchParam.ActiveSearchDocSigner = !string.IsNullOrEmpty(OSearchParam.SearchDocSigner);

                string SearchYearRange = (string)WebEnvironments.Request(SiteId, "YearRange");
                if (!string.IsNullOrEmpty(SearchYearRange))
                {
                    DocYearRangeCls ODocYearRange = DocYearRangeProcessBll.CreateDocYearRangeModel(SiteId, SearchYearRange);
                    OSearchParam.ActiveSearchYearRange = true;
                    OSearchParam.SearchYearRangeFrom = ODocYearRange.FromYear.ToString();
                    OSearchParam.SearchYearRangeTo = ODocYearRange.ToYear.ToString();
                }
                


                OSearchParam.SearchSubject = (string)WebEnvironments.Request(SiteId, "subject");
                if (OSearchParam.SearchSubject == null) OSearchParam.SearchSubject = "";
                OSearchParam.SearchSubject = OSearchParam.SearchSubject.Trim();
                OSearchParam.ActiveSearchSubject = !string.IsNullOrEmpty(OSearchParam.SearchSubject);

                OSearchParam.SortField = (string)WebEnvironments.Request(SiteId, "SortField");
                if (string.IsNullOrEmpty(OSearchParam.SortField)) OSearchParam.SortField = "ReleaseDate";
                OSearchParam.SortType = (string)WebEnvironments.Request(SiteId, "SortType");
                if (string.IsNullOrEmpty(OSearchParam.SortType)) OSearchParam.SortType = "DESC";

                try
                {
                    OSearchParam.VnFromSignDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "sfd")).ToString("yyyy/MM/dd");
                    OSearchParam.VnToSignDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "std")).ToString("yyyy/MM/dd");
                    OSearchParam.SearchSignDate = !string.IsNullOrEmpty(OSearchParam.VnFromSignDate) && !string.IsNullOrEmpty(OSearchParam.VnToSignDate);
                }
                catch { }


                try
                {
                    OSearchParam.VnFromReleaseDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "rfd")).ToString("yyyy/MM/dd");
                    OSearchParam.VnToReleaseDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "rtd")).ToString("yyyy/MM/dd");
                    OSearchParam.SearchReleaseDate = !string.IsNullOrEmpty(OSearchParam.VnFromReleaseDate) && !string.IsNullOrEmpty(OSearchParam.VnToReleaseDate);
                }
                catch { }


                try
                {
                    OSearchParam.VnFromEffectedDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "efd")).ToString("yyyy/MM/dd");
                    OSearchParam.VnToEffectedDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "etd")).ToString("yyyy/MM/dd");
                    OSearchParam.SearchEffectedDate = !string.IsNullOrEmpty(OSearchParam.VnFromEffectedDate) && !string.IsNullOrEmpty(OSearchParam.VnToEffectedDate);
                }
                catch { }


                
                OSearchParam.PageSize = 10;
                try
                {
                    OSearchParam.PageSize = int.Parse(WebEnvironments.Request(SiteId, "PageSize"));
                }
                catch { }
                int PageIndex = 0;
                try
                {
                    PageIndex = int.Parse(WebEnvironments.Request(SiteId, "PageIndex"));
                }
                catch { }
                OSearchParam.PageIndex = PageIndex;
                try
                {
                    OSearchParam.PublishingStatus = int.Parse((string)WebEnvironments.Request(SiteId, "ps"));
                }
                catch
                {
                    OSearchParam.PublishingStatus = 2;
                }

                SearchResultCls OSearchResult = SearchBll.Execute(SiteId, OSearchParam);
                ReturnPaging OReturnPaging = WebPaging.GetPaging(OSearchResult.SearchResultItems.Count, PageIndex, OSearchParam.PageSize, 10, "NextPage", 0);
                SortFieldCls[] SortFields = new SortFieldCls[]{
                    new SortFieldCls("DataSort","Số văn bản"),
                    new SortFieldCls("Subject","Tiêu đề"),
                    new SortFieldCls("DocTypeName","Loại văn bản"),
                    new SortFieldCls("DocFieldName","Lĩnh vực"),
                    new SortFieldCls("DocReleaseFromName","Cơ quan ban hành"),
                    new SortFieldCls("DocSignerName","Người ký"),
                    //new SortFieldCls("SignDate","Ngày ký"),
                    new SortFieldCls("ReleaseDate","Ngày ban hành"),
                    new SortFieldCls("EffectedDate","Ngày hiệu lực"),
                };
                string SelectSortFieldText =
                    "<select id=drpSelectSortField class=drpselect>\r\n";
                for (int iIndex = 0; iIndex < SortFields.Length; iIndex++)
                {
                    if (OSearchParam.SortField.Equals(SortFields[iIndex].Field))
                    {
                        SelectSortFieldText += "  <option selected value=\"" + SortFields[iIndex].Field + "\">" + SortFields[iIndex].Name + "</option>\r\n";
                    }
                    else
                    {
                        SelectSortFieldText += "  <option value=\"" + SortFields[iIndex].Field + "\">" + SortFields[iIndex].Name + "</option>\r\n";
                    }
                }
                SelectSortFieldText += "</select>\r\n";

                SortSizeCls[] SortSize = new SortSizeCls[]{
                    new SortSizeCls("5","05"),
                    new SortSizeCls("10","10"),
                    new SortSizeCls("15","15"),
                    new SortSizeCls("20","20"),
                    new SortSizeCls("25","25"),
                };


                string SelectSortSizeText =
                  "<select id=drpSelectPageSize class=drpselect>\r\n";
                for (int iIndex = 0; iIndex < SortSize.Length; iIndex++)
                {
                    if (OSearchParam.PageSize == int.Parse(SortSize[iIndex].Field))
                    {
                        SelectSortSizeText += "  <option selected value=\"" + SortSize[iIndex].Field + "\">" + SortSize[iIndex].Name + "</option>\r\n";
                    }
                    else
                    {
                        SelectSortSizeText += "  <option value=\"" + SortSize[iIndex].Field + "\">" + SortSize[iIndex].Name + "</option>\r\n";
                    }
                }
                SelectSortSizeText += "</select>\r\n";

                string SelectSortType = " <select id=drpSortType class=drpselect>\r\n" +
                                        "   <option value=\"ASC\">Sắp tăng dần</option>\r\n" +
                                        "   <option value=\"DESC\">Sắp giảm dần</option>\r\n" +
                                        " </select>\r\n";
                if (OSearchParam.SortType.Equals("DESC"))
                {
                    SelectSortType = " <select id=drpSortType class=drpselect>\r\n" +
                                        "   <option value=\"ASC\">Sắp tăng dần</option>\r\n" +
                                        "   <option selected value=\"DESC\">Sắp giảm dần</option>\r\n" +
                                        " </select>\r\n";
                }

                string SelectStatus =
                    " <select id=drpSelectStatus class=drpselect>\r\n" +
                    "   <option value=\"2\" selected>Toàn bộ</option>\r\n" +
                    "   <option value=\"0\">Chờ phát hành</option>\r\n" +
                    "   <option value=\"1\">Đã phát hành</option>\r\n" +
                    " </select>\r\n";

               

                if (OSearchParam.PublishingStatus == 0)
                {
                    SelectStatus =
                    " <select id=drpSelectStatus class=drpselect>\r\n" +
                    "   <option value=\"2\">Toàn bộ</option>\r\n" +
                    "   <option value=\"0\" selected>Chờ phát hành</option>\r\n" +
                    "   <option value=\"1\">Đã phát hành</option>\r\n" +
                    " </select>\r\n";
                }

                if (OSearchParam.PublishingStatus == 1)
                {
                    SelectStatus =
                    " <select id=drpSelectStatus class=drpselect>\r\n" +
                    "   <option value=\"2\">Toàn bộ</option>\r\n" +
                    "   <option value=\"0\">Chờ phát hành</option>\r\n" +
                    "   <option value=\"1\" selected>Đã phát hành</option>\r\n" +
                    " </select>\r\n";
                }

                string Html =
                    " <script language=javascript>\r\n" +
                    "   function ProcessDownload(DocumentId)\r\n"+
                    "   {\r\n"+
                    "       SiteId='"+SiteId+"';\r\n"+
                    "       OAjaxOut=Portal.Cms.Render.CmsDataRenderBll.ServerSideDownloadDocument(SiteId,DocumentId).value;\r\n" +
                    "       if(OAjaxOut.Error)\r\n"+
                    "       {\r\n"+
                    "           alert(OAjaxOut.InfoMessage);\r\n"+
                    "           return;\r\n"+
                    "       }\r\n"+
                    "       window.open(OAjaxOut.RetUrl,'_blank');\r\n"+
                    "   }\r\n"+

                    "   function NextPage(CurrentPageIndex)\r\n" +
                    "   {\r\n" +
                    "       ClientDoSearchDocument(CurrentPageIndex);\r\n" +
                    "   }\r\n" +


                    "   function ClientRequestPublish(DocumentId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       if(confirm('Bạn đã chắc chắn gửi duyệt phát hành chưa?')==false)return;\r\n" +
                    "       document.getElementById('divSendApproved'+DocumentId).innerHTML='Đang xử lý...';\r\n" +
                    "       setTimeout('RealClientRequestPublish(\"'+DocumentId+'\")',10);\r\n"+
                    "   }\r\n" +

                    "   function RealClientRequestPublish(DocumentId)\r\n"+
                    "   {\r\n"+
                    "       SiteId='"+SiteId+"';\r\n"+
                    "       OAjaxOut=Portal.Cms.Render.CmsDataRenderBll.ServerSideSendPublish(SiteId,DocumentId).value;\r\n" +
                    "       document.getElementById('divSendApproved'+DocumentId).innerHTML='';\r\n"+
                    "       if(OAjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(OAjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       document.getElementById('divSendPublish'+DocumentId).innerHTML='';\r\n"+
                    "       alert('Đã gửi vào danh sách chờ duyệt và phát hành!');\r\n"+
                    "   }\r\n"+

                    "   function ClientAddShortCut(GroupDataId)\r\n"+
                    "   {\r\n"+
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       OAjaxOut=Portal.Cms.Render.CmsDataRenderBll.ServerSideAddShortCut(SiteId,'document',GroupDataId).value;\r\n" +
                    "       if(OAjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(OAjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       alert(OAjaxOut.InfoMessage);\r\n" +
                    "   }\r\n" +

                    " </script>\r\n";
                

                   string PagingText = OSearchResult.PaggingText;
                   string ParentDataId = (string)WebEnvironments.Request(SiteId, "parent");


                   Html +=
                       GetPlugInJavascript(SiteId, ParentDataId) +
                       //" <div id=divActionUpdateForm style=\"display:none;\">" + DrawUpdateForm(SiteId, gid).HtmlContent + "</div>\r\n" +
                       //" <div id=divActionAddForm style=\"display:none;\">" + DrawAddForm(SiteId, gid).HtmlContent + "</div>\r\n" +
                       " <div id=divActionChangeAvatarForm  style=\"display:none;\">" + DrawChangeAvatarForm(SiteId, gid).HtmlContent + "</div>\r\n" +
                       " <div id=divActionAttachDocForm  style=\"display:none;\">" + DrawChangeAttachDocForm(SiteId, gid).HtmlContent + "</div>\r\n" +



                    " <div class=CssListCategory id=divListForm>\r\n";
                   if (AllowManage)
                   {
                       Html +=
                           " <div class=RelationFunction>\r\n" +
                           "    <ul>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/menu.png\"><a href=\"DocumentType.aspx?gid=" + OGroupData.GroupDataId + "\"><div>Loại văn bản</div></a></li>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/signer.png\"><a href=\"DocumentSigner.aspx?gid=" + OGroupData.GroupDataId + "\"><div>Người ký văn bản</div></a></li>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/Office.png\"><div><a href=\"DocumentReleaseFrom.aspx?gid=" + OGroupData.GroupDataId + "\">Cơ quan ban hành</div></a></li>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/Field.png\"><a href=\"DocumentField.aspx?gid=" + OGroupData.GroupDataId + "\"><div>Lĩnh vực văn bản</div></a></li>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/Year.png\"><a href=\"DocumentYearRange.aspx?gid=" + OGroupData.GroupDataId + "\"><div>Khoảng thời gian</div></a></li>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/DocRelationType.png\"><a href=\"DocumentRelationType.aspx?gid=" + OGroupData.GroupDataId + "\"><div>Kiểu quan hệ</div></a></li>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/Shortcut.png\"><a href=\"javascript:ClientUpdateIndex('" + OGroupData.GroupDataId + "');\"><div>Index</div></a></li>\r\n" +
                           "        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/Add.png\"><a href=\"javascript:ClientAdd('" + OGroupData.GroupDataId + "');\"><div>Thêm văn bản</div></a></li>\r\n" +
                           //"        <li><img class=imagebutton src=\"" + ButtonUrl + "/cms/Back.png\"><a href=\"javascript:window.open('RootGroupData.aspx?DataType=document','_self');\"><div>Về trang chủ</div></a></li>\r\n" +
                           "    </ul>\r\n" +
                           "</div>\r\n";
                   }

                
                Html+=
                    " <h3>" + OGroupData.GroupDataName + "</h3>\r\n" +
                    " <div class=CssNewsHeading>Tổng số có " + OSearchResult.TotalFound + " văn bản trong chuyên mục</div>\r\n" +
                    " <div class=CssSort>Trạng thái: "+SelectStatus+" - Sắp xếp: " + SelectSortFieldText + " - Kiểu: " + SelectSortType + " - văn bản " + SelectSortSizeText + " / trang <input type=button class=button value=\"Lọc\" onclick=\"javascript:NextPage(0);\"></div>\r\n" +
                     PagingText+
                    " <div class=CssResultItems>\r\n"+
                    " <table> \r\n";

                string WebPartLayoutButtonUrl = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);
                int CountIndex = OSearchResult.StartIndex;
                for (int iIndex = 0; iIndex < OSearchResult.SearchResultItems.Count; iIndex++)
                {
                    string NewImageText = "";
                    if (OSearchResult.SearchResultItems[iIndex].IsNew == 1)
                    {
                        //NewImageText = "<img class=imgthumb src=\"Resources/Images/Newred.png\"></img>";
                    }
                    string ReleaseButton ="";
                    //if (OSearchResult.SearchResultItems[iIndex].NeedApproved == 0)
                    //{
                    //    ReleaseButton = 
                    //        "<div id=\"divSendPublish" + OSearchResult.SearchResultItems[iIndex].DocumentId + "\"><input type=button class=button value=\"Gửi duyệt phát hành\" onclick=\"javascript:ClientRequestPublish('" + OSearchResult.SearchResultItems[iIndex].DocumentId + "');\"></div>\r\n";
                    //}
                    if (AllowPublish)
                    {
                        //ReleaseButton =
//                          "<input type=button class=button value=\"Phát hành\" onclick=\"javascript:ClientPublic('" + OSearchResult.SearchResultItems[iIndex].DocumentId + "');\">";
                        if (OSearchResult.SearchResultItems[iIndex].IsPublic == 1)
                        {
                            ReleaseButton =
                                "<input type=button class=button value=\"Ngưng phát hành\" onclick=\"javascript:ClientUnPublic('" + OSearchResult.SearchResultItems[iIndex].DocumentId + "');\">";
                        }
                    }
                    string SubMenuButton = "";
                    if (OGroupData.AllowSub == 1)
                    {
                        SubMenuButton =
                            "<input style=\"width:80px;font-size:12px;\" type=button class=button value=\"Dữ liệu con\" onclick=\"javascript:window.open('InputData.aspx?gid=" + OGroupData.GroupDataId + "&parent=" + OSearchResult.SearchResultItems[iIndex].DocumentId + "','_self');\">";
                    }
                   
                    Html +=
                        " <tr> \r\n" +
                        "    <td style=\"width:40px;vertical-align:top\">" + NewImageText + "</td> \r\n" +
                        "    <td> \r\n" +
                        "        <div class=NewsTitle><a href=\"PreviewCmsData.aspx?gid=" + OGroupData.GroupDataId + "&CmsDataId=" + OSearchResult.SearchResultItems[iIndex].DocumentId + "\">" + (CountIndex + 1) + ". " + ProcessHighLight(OSearchParam.SearchSubject, OSearchResult.SearchResultItems[iIndex].Subject) + "</a></div> \r\n" +
                        "        <div>Số: <span class=DocNo>" + ProcessHighLight(OSearchParam.SearchDocumentNo, OSearchResult.SearchResultItems[iIndex].DocumentNo) + "</span></div> \r\n" +
                        "        <div>Loại văn bản: <span class=ReleaseFrom><a href=\"" + ORenderInfo.JumpPageAspx + "?gid=" + gid + "&doctype=" + OSearchResult.SearchResultItems[iIndex].DocTypeId + "\">" + OSearchResult.SearchResultItems[iIndex].DocType + "</a></span></div> \r\n" +
                        "        <div>Đơn vị ban hành: <span class=ReleaseFrom><a href=\"" + ORenderInfo.JumpPageAspx + "?gid=" + gid + "&ReleaseFrom=" + OSearchResult.SearchResultItems[iIndex].DocReleaseFromId + "\">" + OSearchResult.SearchResultItems[iIndex].DocReleaseFrom + "</a></span></div> \r\n" +
                        "        <div>Người ký: <span class=ReleaseFrom><a href=\"" + ORenderInfo.JumpPageAspx + "?gid=" + gid + "&singer=" + OSearchResult.SearchResultItems[iIndex].DocSignerId + "\">" + OSearchResult.SearchResultItems[iIndex].DocSigner + "</a></span></div> \r\n" +
                        "        <div>Ban hành ngày <span class=CssDate>" + OSearchResult.SearchResultItems[iIndex].ReleaseDate + "</span> | Hiệu lực <span class=CssDate>" + OSearchResult.SearchResultItems[iIndex].EffectedDate + "</span></div> \r\n" +
                        //"        <div>Ngày ký: <span class=CssDate>" + OSearchResult.SearchResultItems[iIndex].SignDate + "</span> | Ban hành ngày <span class=CssDate>" + OSearchResult.SearchResultItems[iIndex].ReleaseDate + "</span> | Hiệu lực <span class=CssDate>" + OSearchResult.SearchResultItems[iIndex].EffectedDate + "</span></div> \r\n" +
                        "        <div><span class=CssTrichYeu>Trích yếu: </span><span class=CssTrichYeuDetail>" + ProcessHighLight(OSearchParam.SearchSubject, OSearchResult.SearchResultItems[iIndex].Description) + "</span></div> \r\n" +

                        "        <div class=CssStatusText id=\"divStatusText" + OSearchResult.SearchResultItems[iIndex].DocumentId + "\">" + (OSearchResult.SearchResultItems[iIndex].IsPublic == 1 ? "Đã phát hành" : "Chờ phát hành") + "</div>\r\n" +
                        "        <div id=\"divSendApproved" + OSearchResult.SearchResultItems[iIndex].DocumentId + "\" class=\"CssProcessing\"></div>\r\n"+
                        "        <div class=download>\r\n" +
                        "           <table>\r\n" +
                        "               <tr>\r\n" +
                        "                   <td style=\"vertical-align:top\"><a href=\"javascript:ProcessDownload('" + OSearchResult.SearchResultItems[iIndex].DocumentId + "');\"><img alt=\"Download tài liệu gắn kèm\" title=\"Download tài liệu gắn kèm\" class=image src=\""+WebPartLayoutButtonUrl+"/cms/download.png\"></a></td>\r\n" +
                        "                   <td style=\"vertical-align:top;padding-top:5px;margin-left:10px;\"><div id=divStatusText" + OSearchResult.SearchResultItems[iIndex].DocumentId + "><div id=\"divButton" + OSearchResult.SearchResultItems[iIndex].DocumentId + "\">" + ReleaseButton + "</div></div></td>\r\n";
                    if (AllowManage)
                    {
                        Html +=
                        "                   <td style=\"vertical-align:top;padding-top:5px;margin-left:10px;\"><input type=button class=button value=\"Sửa\" onclick=\"javascript:ClientUpdateDocument('" + gid + "','" + OSearchResult.SearchResultItems[iIndex].DocumentId + "');\"></td>\r\n" +
                        "                   <td style=\"vertical-align:top;padding-top:5px;margin-left:10px;\"><input type=button class=button value=\"Xóa\" onclick=\"javascript:ClientDelete('" + gid + "','" + OSearchResult.SearchResultItems[iIndex].DocumentId + "');\"></td>\r\n" +
                        "                   <td style=\"vertical-align:top;padding-top:5px;margin-left:10px;\">" + SubMenuButton + "</td>\r\n" +
                        "                   <td style=\"vertical-align:top;padding-top:5px;margin-left:10px;\"><input type=button class=button value=\"Tài liệu\" onclick=\"javascript:ClientAttachDoc('" + gid + "','" + OSearchResult.SearchResultItems[iIndex].DocumentId + "');\"></td>\r\n";
                    }
                    Html+=
                        "               </tr>\r\n"+
                        "           </table>\r\n"+
                        "       </div> \r\n" +
                        "   </td> \r\n" +
                        "</tr> \r\n";
                    CountIndex++;
                }
                Html +=
                    "</table>\r\n" +
                    "</div>\r\n" +
                    PagingText +

                    " <div class=\"clr\"></div>\r\n" +
                    " </div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static void SetCollapseExpand(string SiteId, string DivId, string Expand)
        {
            WebSessionUtility.SetSession(SiteId, DivId, bool.Parse(Expand));
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDownloadAttachFile(string SiteId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, DataId);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                OAjaxOut.RetUrl = OCmsData.GetAttachDocUrl(SiteId,WebConfig.HttpDataRoot(OSiteParam));
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        public static AjaxOut ViewDocumentDetail(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string Id = (string)WebEnvironments.Request(SiteId, "Id");
                string Back = (string)WebEnvironments.Request(SiteId, "Back");
                if (string.IsNullOrEmpty(Id)) throw new Exception("Tài liệu không tìm thấy! Truy vấn không hợp lệ");
                if (string.IsNullOrEmpty(Back)) throw new Exception("Tham số truy vấn không hợp lệ");
                string gid = (string)WebEnvironments.Request(SiteId, "gid");

                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, Id, true, false);
                if (OCmsData == null) throw new Exception("Tài liệu không tìm thấy! Truy vấn không hợp lệ");
                string BackUrl = Back+"?gid="+gid;
                string BackAspx = ORenderInfo.JumpPageAspx;
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string WebPartLayoutButtonUrl = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);
                //string PreviewImage = WebPartLayoutButtonUrl+"/cms/preview.png";
                //if (OCmsData.AttachedSearchable==0)
                //{
                //    PreviewImage = WebPartLayoutButtonUrl+"/cms/PreviewJpg.png";
                //}

                string NewImageText = "";
                if (OCmsData.IsNew == 1)
                {
                    //NewImageText = "<img class=imgthumb src=\"Resources/Images/Newred.png\"></img>";
                }

                string ButtonUrl = WebConfig.GetButtonIconRoot(OSiteParam);
                string LiProcessWorkflow = "<li><img class=imagebutton src=\"" + ButtonUrl + "/Workflow.png\"><a href=\"javascript:ClientStartWorkflow('" + OCmsData.DataId + "');\"><div>Khởi tạo quy trình</div></a></li>\r\n";
                bool HasStarted = WorkflowUtilities.CheckHasStartWorkflow(SiteId, OCmsData.DataId);
                if (HasStarted)
                {
                    Portal.Workflow.Bussiness.WorkflowBll.GetWorkflowCls 
                        OWorkflow = WorkflowUtilities.GetWorkflowActionInfo(SiteId, OCmsData.DataId);
                    if (OWorkflow != null)
                    {
                        LiProcessWorkflow = "<li><img class=imagebutton src=\"" + ButtonUrl + "/Workflow.png\"><a href=\"javascript:ProcessWorkflow('" + OWorkflow.WorkflowDefId + "','" + OWorkflow.WorkflowActionId + "','" + OCmsData.DataId + "');\"><div>Xử lý quy trình</div></a></li>";
                    }
                    else
                    {
                        LiProcessWorkflow = "";
                    }
                }
             
                string Html =
                    " <script language=javascript>\r\n" +
                    "   function ClientAddShortCut(DataId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       OAjaxOut=Portal.Cms.Render.CmsDataRenderBll.ServerSideAddShortCutView(SiteId,'ViewDocument',DataId).value;\r\n" +
                    "       if(OAjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(OAjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       alert(OAjaxOut.InfoMessage);\r\n" +
                    "   }\r\n" +

                    "   function ClientDownloadAttachFile(DataId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideDownloadAttachFile(SiteId,DataId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_blank');\r\n" +
                    "   }\r\n" +

                    "   function ClientAddRelationDocument(GroupDataId,DataId,RelationTypeId)\r\n"+
                    "   {\r\n"+
                    "       SiteId='"+SiteId+"';\r\n"+
                    "       documentNo=document.getElementById('txtRelationTypeText'+RelationTypeId).value;\r\n" +
                    "       documentNo=documentNo.trim();\r\n"+
                    "       if(documentNo=='')\r\n"+
                    "       {\r\n"+
                    "           alert('Chưa nhập số văn bản liên quan!');\r\n"+
                    "           document.getElementById('txtRelationTypeText'+RelationTypeId).focus();\r\n"+
                    "           return;\r\n"+
                    "       }\r\n"+
                    "       AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideAddRelationDocument(SiteId,GroupDataId, DataId, RelationTypeId, documentNo, '"+BackAspx+"').value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_self');\r\n"+
                    "   }\r\n"+

                    "   function ClientDeleteRelation(RelationDataId,GroupDataId,DataId,RelationTypeId)\r\n" +
                    "   {\r\n"+
                    "       SiteId='"+SiteId+"';\r\n"+
                    "       if(confirm('Bạn đã chắc chắn xóa chưa?')==false)return;\r\n"+
                    "       AjaxOut = Portal.Cms.Render.CmsDataRenderBll.ServerSideDeleteRelationDocument(SiteId,RelationDataId, GroupDataId, DataId, RelationTypeId, '" + BackAspx + "').value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_self');\r\n"+
                    "   }\r\n"+

                    "   function ClientStartWorkflow(DataId)\r\n"+
                    "   {\r\n"+
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       if(confirm('Bạn đã chắc chắn khởi tạo quy trình chưa?')==false)return;\r\n" +
                    "       AjaxOut = Portal.Cms.Render.CmsDataRenderBll.`(SiteId, DataId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_self');\r\n" +
                    "   }\r\n"+

                    "    function ProcessWorkflow(WorkflowDefId,WorkflowActionId,RecordId)\r\n" +
                    "    {\r\n" +
                    "        SiteId='" + SiteId + "';\r\n" +
                    "        AjaxOut=Portal.Cms.Render.CmsDataRenderBll.ServerSideProcessAjaxNextLink(SiteId,WorkflowDefId,WorkflowActionId,RecordId).value;\r\n" +
                    "        document.getElementById('content_workflow').innerHTML=AjaxOut.HtmlContent;\r\n" +
                    "        document.getElementById('content_workflow').style.display='block';\r\n" +
                    //"        document.getElementById('divMainForm').style.display='none';\r\n" +
                    "    }\r\n" +
                    " </script>\r\n" +

                     WorkflowBll.ServerSideGetPlugInJavascriptDoNextLink(SiteId, "content_workflow", "divMainForm") +
                    " <div id=divMainForm>\r\n"+
                    " <div class=RelationFunction>\r\n" +
                    "    <ul>\r\n" +
                    "        <li><img class=imagebutton src=\"" + ButtonUrl + "/Back.png\"><a href=\"javascript:window.open('" + BackUrl + "','_self');\"><div>Quay lại</div></a></li>\r\n" +
                    "        <li><img class=imagebutton src=\"" + ButtonUrl + "/Shortcut.png\"><a href=\"javascript:ClientAddShortCut('" + OCmsData.DataId + "');\"><div>Tạo shortcut</div></a></li>\r\n" +
                    LiProcessWorkflow +
                    "    </ul>\r\n" +
                    " </div>\r\n"+

                    " <div class=CssListCategory> \r\n" +
                    " <h3>" + OCmsData.Subject + "</h3>\r\n"+
                    //" <div class=function style=\"text-align:right;margin-right:10px;\"><input type=button class=button onclick=\"javascript:window.open('" + BackUrl + "','_self');\" value=\"Quay lại\"></div> \r\n" +
                    " <table> \r\n" +
                    "     <tr> \r\n" +
                    "         <td style=\"width:40px;vertical-align:top\">"+NewImageText+"</td> \r\n" +
                    "         <td> \r\n" +
                    "             <div class=viewdetail> \r\n" +
                    "             <table> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Số văn bản * :</td> \r\n" +
                    "                     <td class=col2><span class=DocNo>" + OCmsData.DataAlias + "</span></td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Trích yếu * :</td> \r\n" +
                    "                     <td class=col2>" + OCmsData.Description + "</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Lĩnh vực * :</td> \r\n" +
                    "                     <td class=col2>" + OCmsData.DocFieldName + "</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Loại văn bản * :</td> \r\n" +
                    "                     <td class=col2>" + OCmsData.DocTypeName + "</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Cơ quan ban hành * :</td> \r\n" +
                    "                     <td class=col2>" + OCmsData.DocReleaseFromName + "</td> \r\n" +
                    "                 </tr> \r\n" +
                    //"                 <tr> \r\n" +
                    //"                     <td class=col1>Ngày ký:</td> \r\n" +
                    //"                     <td class=col2><span class=CssDate>" + OCmsData.SignDate + "</span</td> \r\n" +
                    //"                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Ngày ban hành * :</td> \r\n" +
                    "                     <td class=col2><span class=CssDate>" + OCmsData.ReleaseDate + "</span</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Ngày hiệu lực:</td> \r\n" +
                    "                     <td class=col2><span class=CssDate>" + OCmsData.EffectedDate + "</span</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Thay thế văn bản:</td> \r\n" +
                    "                     <td class=col2></td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Sửa chữa văn bản:</td> \r\n" +
                    "                     <td class=col2></td> \r\n" +
                    "                 </tr> \r\n" +
                    //"                 <tr> \r\n" +
                    //"                     <td class=col1>Trích yếu:</td> \r\n" +
                    //"                     <td class=col2><span class=CssTrichYeuDetail>" + OCmsData.Description + "</span></td> \r\n" +
                    //"                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1></td> \r\n" +
                    "                     <td class=col2>Số lần xem: <span class=CssTotalView>" + OCmsData.TotalPreview.ToString("#,##0") + "</span> | Số lần tải: <span class=CssTotalDownload>" + OCmsData.TotalDownload.ToString("#,##0") + "</span></td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Tải về máy:</td> \r\n" +
                    "                     <td class=col2><img onclick=\"javascript:ClientDownloadAttachFile('" + OCmsData.DataId + "');\" style=\"border:none;\" alt=\"Download tài liệu gắn kèm\" title=\"Download tài liệu gắn kèm\" class=image src=\""+WebPartLayoutButtonUrl+"/cms/download.png\"></div></td> \r\n" +
                    "                 </tr> \r\n" +
                    "             </table> \r\n" +
                    "             </div> \r\n" +
                    "         </td> \r\n" +
                    "     </tr> \r\n" +
                    "</table> \r\n";
                bool AllowManage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupDataPermission.StaticId, GroupDataPermission.funcManage, gid, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                if (AllowManage)
                {
                    RelationTypeCls[] RelationTypes = RelationTypeProcessBll.ReadingRelationType(SiteId, OCmsData.frkGroupDataId);
                    for (int iIndex = 0; iIndex < RelationTypes.Length; iIndex++)
                    {
                        CmsDataRelationCls[] CmsDataRelations = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingDocumentRelation(SiteId, OCmsData.DataId, RelationTypes[iIndex].RelationTypeId);
                        Html +=
                        " <h3>" + RelationTypes[iIndex].RelationTypeName + "</h3>\r\n" +
                        " <div class=CssRelationDivFunc>Số văn bản: <input type=textbox id=\"txtRelationTypeText" + RelationTypes[iIndex].RelationTypeId + "\" class=textbox><input type=button class=button value=\"Đưa vào\" onclick=\"javascript:ClientAddRelationDocument('" + OCmsData.frkGroupDataId + "','" + OCmsData.DataId + "','" + RelationTypes[iIndex].RelationTypeId + "');\"></div>\r\n" +
                        " <div class=relationdoc>\r\n" +
                        " <ul>\r\n";
                        for (int zIndex = 0; zIndex < CmsDataRelations.Length; zIndex++)
                        {
                            Html +=
                                "<li>\r\n" +
                                "   <img class=\"imgdelete\" onclick=\"javascript:ClientDeleteRelation('" + CmsDataRelations[zIndex].RelationDataId + "','" + OCmsData.frkGroupDataId + "','" + OCmsData.DataId + "','" + RelationTypes[iIndex].RelationTypeId + "');\" src=\"resources/images/delete.png\"> Số: <span class=DocNo>" + CmsDataRelations[zIndex].DataAlias + "</span> - <a href=\"?gid=" + gid + "&id=" + CmsDataRelations[zIndex].DataId + "&back=" + BackAspx + "\">" + CmsDataRelations[zIndex].Subject + "</a>\r\n" +
                                "</li>\r\n";
                        }
                        Html +=
                        "</ul>\r\n" +
                        "</div>\r\n";
                    }
                }
                Html +=
                   " <div class=\"clr\"></div>\r\n" +
                   " </div>" +
                   "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        //[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        //public AjaxOut ServerSideProcessAjaxNextLink(
        //    string SiteId,
        //    string WorkflowDefId,
        //    string WorkflowActionId,
        //    string RecordId)
        //{
        //    AjaxOut OAjaxOut = new AjaxOut();
        //    try
        //    {
        //        WebSessionUtility.CheckSessionTimeOut();
        //        new WorkflowBll().CheckDoNextLinkRunAtServer(SiteId, WorkflowActionId);
        //        string Html = new AjaxWorkflowTaskNextLink().Draw(SiteId, WorkflowDefId, WorkflowActionId, RecordId, LinkId);
        //        OAjaxOut.HtmlContent = Html;
        //    }
        //    catch (Exception ex)
        //    {
        //        OAjaxOut.Error = true;
        //        OAjaxOut.HtmlContent = ex.Message.ToString();
        //        OAjaxOut.InfoMessage = ex.Message.ToString();
        //    }
        //    return OAjaxOut;
        //}

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideStartWorkflow(
            string SiteId, 
            string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, DataId);
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).SendForPublish(SiteId, DataId);
                OAjaxOut.RetUrl = "?gid=" + OCmsData.frkGroupDataId + "&id=" + OCmsData.DataId + "&back=DocumentInputData.aspx";
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideAddRelationDocument(
            string SiteId, 
            string GroupDataId, 
            string SrcDataId, 
            string RelationTypeId, 
            string documentNo,
            string BackAspx)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, documentNo);
                if (OCmsData == null)
                {
                    throw new Exception("Số văn bản liên quan không hợp lệ! Không tìm thấy số văn bản này!");
                }
                if (OCmsData.Equals(SrcDataId))
                {
                    throw new Exception("Số văn bản liên quan không hợp lệ! Văn bản liên quan không thể chính là văn bản này!");
                }
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).AddDocumentRelation(SiteId, SrcDataId, OCmsData.DataId, RelationTypeId);
                OAjaxOut.RetUrl = "?gid=" + GroupDataId + "&id=" + SrcDataId + "&back=" + BackAspx;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDeleteRelationDocument(
            string SiteId,
            string RelationDataId,
            string GroupDataId,
            string SrcDataId,
            string RelationTypeId,
            string BackAspx)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).DeleteDocumentRelation(SiteId,  RelationDataId);
                OAjaxOut.RetUrl = "?gid=" + GroupDataId + "&id=" + SrcDataId + "&back=" + BackAspx;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string ServerSideGetNewDataId(string SiteId)
        {
            return System.Guid.NewGuid().ToString();
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public AjaxOut ServerSideDownloadDocument(string SiteId,string DocumentId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, DocumentId);
                OAjaxOut.RetUrl = OCmsData.GetAttachDocUrl(SiteId,WebConfig.HttpDataRoot(OSiteParam));
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public AjaxOut ServerSideSendPublish(string SiteId, string DocumentId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).SendForPublish(SiteId, DocumentId);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideAddShortCut(string SiteId,string LinkType, string GroupDataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                string UserId = WebSessionUtility.GetCurrentLoginUser().UserId;
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                UserQuickLinkCls OUserQuickLink = new UserQuickLinkCls();
                OUserQuickLink.frkUserId = UserId;
                OUserQuickLink.LinkType = LinkType;
                OUserQuickLink.SortIndex = 0;
                OUserQuickLink.Subject = "Csdl: " + OGroupData.GroupDataName;
                OUserQuickLink.ObjectId = GroupDataId;
                OUserQuickLink.LinkUrl = "modules/cms/DocumentInputData.aspx?gid=" + GroupDataId;
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).AddUserQuickLink(SiteId, OUserQuickLink);
                OAjaxOut.InfoMessage = "Tạo shortcut ra màn hình chính thành công!";
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = "Đã có shortcut này không tạo thêm nữa";
                OAjaxOut.HtmlContent = "Đã có shortcut này không tạo thêm nữa";
                ex.Source = "";
            }

            return OAjaxOut;
        }



        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideAddShortCutView(string SiteId, string LinkType, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                string UserId = WebSessionUtility.GetCurrentLoginUser().UserId;
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, DataId);
                UserQuickLinkCls OUserQuickLink = new UserQuickLinkCls();
                OUserQuickLink.frkUserId = UserId;
                OUserQuickLink.LinkType = LinkType;
                OUserQuickLink.SortIndex = 0;
                OUserQuickLink.Subject = "Văn bản: " + OCmsData.DataAlias + " / " + OCmsData.Subject;
                OUserQuickLink.ObjectId = DataId;
                OUserQuickLink.LinkUrl = "modules/cms/PreviewCmsData.aspx?gid=" + OCmsData.frkGroupDataId + "&CmsDataId=" + OCmsData.DataId + "&back=home.aspx";
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).AddUserQuickLink(SiteId, OUserQuickLink);
                OAjaxOut.InfoMessage = "Tạo shortcut ra màn hình chính thành công!";
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = "Đã có shortcut này không tạo thêm nữa";
                OAjaxOut.HtmlContent = "Đã có shortcut này không tạo thêm nữa";
                ex.Source = "";
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideIndex(string SiteId, string GroupDataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ExecuteIndexService(SiteId);
                OAjaxOut.InfoMessage = "Cập nhật index tìm kiếm thành công!";
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                ex.Source = "";
            }

            return OAjaxOut;
        }

    }
}
